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

  • 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.

  • 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.

  • It says that "Mouse is not an object name"

  • 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.

  • Ok, I have it folling my mouse, but its not rotation around the point I want it too.

  • 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.

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • try using "min" and/or "max" expression

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)