need help with converting XY motion to rotational direction

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • There must be a simple equation for this, but I can't think of it. Basically, I have an enemy that rotates 360 degrees, and I want that rotation to be affected by the player's XY movement. So, in the following GIF, I want the eel to inherit a bit of Spryke's movement when it eats Spryke. In this example, Spryke is moving right (X positive) and up (Y negative) when she gets eaten, and I'd like to rotate the eel a little clockwise to make it feel like Spryke's heft has pushed the eel up a bit, rather than the eel seeming unaffected by her movement.


    Please login to see this picture.


    In the next example, Spryke is moving the opposite way - a little left (X negative) and down (Y positive) - but because of the way the eel is facing, it should still move clockwise, but this time to make it feel like the eel is being pushed down.


    Please login to see this picture.


    So basically I need some sort of equation to consider Spryke's X & Y movement, and the eel's current angle, and output whether the eel's angle should decrease (clockwise) or increase (anticlockwise) to broadly match Spryke's direction. These eels can also come out of walls and ceilings, so an eel may appear in any of the 4 quadrants of a 360 degree circle. Can anyone help me with this please? The answer may well already be on MuddyMole's great Please login to see this link., but I can't figure out which equations I would need

    Please login to see this link.
    My Fusion Tools: Please login to see this link. | Please login to see this link. | Please login to see this link.

    Edited 5 times, last by Volnaiskra (September 24, 2023 at 3:35 PM).

  • you're right - it's one of the formulae on the page, the one about finding the difference between two angles

    Code
    differenceAB = ((angleA - angleB + 540) mod 360) - 180

    instead of thinking of the eel as a point though, think of it as a vector looking in the direction of the player sprite - so the angleA would be the player's movement angle and angleB is the angle between the player and the eel. The number being positive/negative will indicate whether it is clockwise/anticlockwise

  • Right on - thanks! As it happens I'm already using this equation in a few other places for these eels, but I wouldn't have thought of using it here. As you point out, the key was to think about it in terms of comparing two vectors, rather than focusing on X & Y values. Thanks again :)

    Please login to see this link.
    My Fusion Tools: Please login to see this link. | Please login to see this link. | Please login to see this link.

    Edited once, last by Volnaiskra (September 26, 2023 at 9:32 AM).

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!