How do rotate a sprite within certain angles?

0 favourites
  • 6 posts
From the Asset Store
Simple resize and rotate events for any sprite, quick and easy event sheet that you can use for your own projects.
  • I have a cannon sprite that is set to rotate towards the mouse position.

    Every Tick-> Cannon.Set Angle -> Mouse.X & Mouse.Y

    This works great the cannon sprite rotates around following the mouse.

    I want it to only rotate between certain angles though. I don't want it to be able to rotate straight up, down, or behind.

    So I add a condition that it only rotate when the cannon is between two angles (X&Y).

    This brings the problem that when it reaches either X or Y it stop following the mouse all together.

    Any ideas on how to remedy this?

  • set another sprite at the same position of the cannon, set its angle towards mouse position.

    Set the cannon angle to the sprites angle but with a condition where you check if its in your angle range.

    I think there is an more effiecent way but i dont worked a lot with angles yet so this is the only methode that comes in my mind right now.

    Maybe someone other knows a better way for it.

  • Thank you so much, I was racking my brain like crazy. It may be crude but damn if it don't work beautifully.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • you could do it like this

  • , that's how I did it originally. The problem with that is when they have the mouse on top of the cannon it wont move. Like if the mouse is below your cannon it wont move.

  • Have you tried using clamp?

    clamp(x, lower, upper)

    Return lower if x is less than lower, upper if x is greater than upper, else return x.

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