How do I have a 'cannon' follow my mouse?

Get help using Construct 2

Post » Mon Jul 06, 2015 6:07 pm

I am making a Angry Bird style game and was wondering how I could get the 'Cannon' to follow my mouse like rotation wise, so when the Cursor moves up the cannon faces up.
B
5
Posts: 25
Reputation: 277

Post » Mon Jul 06, 2015 6:16 pm

Every Tick, set angle of cannon to position (Mouse.X, Mouse.Y). I'm not in front of a computer with Construct 2, but I think that's what I did for my top down shooter character to always point at the mouse.
B
11
S
2
G
1
Posts: 79
Reputation: 842

Post » Mon Jul 06, 2015 6:20 pm

It says that "Mouse is not an object name"
B
5
Posts: 25
Reputation: 277

Post » Mon Jul 06, 2015 6:29 pm

Double click in the layout and add the Mouse object so it can be used in the game. Now it should appear in the Auto Complete and you should see it in the list of objects. You only need to add it to one layout and it is added automatically for the entire project.
B
11
S
2
G
1
Posts: 79
Reputation: 842

Post » Mon Jul 06, 2015 6:29 pm

Ok, I have it folling my mouse, but its not rotation around the point I want it too.
B
5
Posts: 25
Reputation: 277

Post » Mon Jul 06, 2015 6:35 pm

Is it rotating around the center of the sprite? I forget what Construct 2 uses as the basis for its rotation, but it might be the Origin image point. Double click the sprite to open the sprite editor, then towards the bottom left there is an icon that opens the image point editor (when it opens, you might have to move some windows around to find it). You can move the Origin image point (image point number 0) to wherever you want the sprite to rotate around.
B
11
S
2
G
1
Posts: 79
Reputation: 842

Post » Mon Jul 06, 2015 6:39 pm

Thank you, now one final question its there a way to lock the rotation so it can only rotate 180 degrees otherwise the cannon will go into the ground.
B
5
Posts: 25
Reputation: 277

Post » Mon Jul 06, 2015 6:42 pm

try using "min" and/or "max" expression
Image Image
B
26
S
15
G
142
Posts: 881
Reputation: 74,060

Post » Mon Jul 06, 2015 6:44 pm

You can add conditions to the event. So:

Every Tick
Mouse.X > Cannon.X

I think that should work. So the game only does the action if the mouse is higher up on the screen that the cannon. You might have to reference the cannon's origin image point, though.
B
11
S
2
G
1
Posts: 79
Reputation: 842


Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 3 guests