Jump to content
A 2021 backup has been restored. Forums are closed and work in progress. Join our Discord server for more updates! ×
SoaH City Message Board

Angle on Direction of Travel? [MMF2]


Asuma

Recommended Posts

RotationExample.png

I'm trying to achieve this type of rotation. I know there's LarkSS missile example, but his seems rotate towards a point. I just need something to rotate in the direction it's traveling in. I'm using the emeralds movement in SW as I want the objects movement as I want the object to move around the player.

Link to comment
Share on other sites

Looks simple enough. The following assumes you are using degrees and not radians for your angles.

Start with Phase = 0

Start with OutwardShift = 0

every frame increment phase by 1. If it reaches 360 (or better yet some multiple thereof if you want to have better control over the speed of rotation) set it back to 0 before the incrementation event.

Increase OutwardShift every frame by some constant value.

every frame once the timing value increasing is done, set the following:

TrueShift = Max((OutwardShift^0.5), constant representing the limit of the shift)

For the first of the 4 rotating objects...

xPos = shift * cos(phase)

yPos = shift * sin(phase)

For the second

xPos = shift * cos(phase + 90)

yPos = shift * sin(phase + 90)

For the third

xPos = shift * cos(phase + 180)

yPos = shift * sin(phase + 180)

For the fourth

xPos = shift * cos(phase + 270)

yPos = shift * cos(phase + 270)

And that should achieve roughly what you are describing. I think. Truth be told, it might actually rotate counterclockwise instead, but you can fix that just by reversing the phase incrementation (IE counting down from whatever).

Also, if you want 7 emeralds, start from zero and add (360/7) to the phase shift in the individual placement of objects each time instead of 90.

Aaaand holy crap, I just used trig to make a swastika.

Link to comment
Share on other sites

Uh, I thought he just wanted to figure out how to make the objects rotate toward their movement angle, not create that movement, though I may be mistaken.

In any case, if you want to make an object rotate to where it's moving and know the X and Y speeds, you can get the angle from 0,0 to speedX,speedY. You can use Damizean's angle calculator by setting the Xdiff to speedX and the Ydiff to speedY, and then calculating the angle.

Or, just do the MMF2 equivalent of this:

Atan2( speedX, speedY )

Would be something like:

Atan( speedY / speedX )

...with different checks for angles outside of the first quadrant and consideration for MMF2's inversed Y axis.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...