Posted By
|
Message
|
ELC_Games
Registered 30/11/2008
Points 17
|
18th August, 2010 at 07:37:30 -
Lately, I've been trying my hand at some of the more advanced parts of the event editor, specifically the Expression Editor. Thanks to Sketchy's list of formulas, I was able to break down and understand some of the basic trig.
I came across a small problem while trying to use one of the formulas to create an orbiting moon, though.
This was the equation given for setting the angle of the moon: Angle + (360 / (2 * Pi * Distance / Speed))
I'm not entirely sure what to enter for the "Distance" part of the equation. I looked back and tried to use the Pythagoras' theorum method, and even tried to use the Advanced Direction Object, but I'm still pretty stumped.
Does anyone know a surefire equation for calculating the distance between two objects?
Edited by ELC_Games
There are those who live to win, and those who win to live. There is no in between.
|
Sketchy Cornwall UK
Registered 06/11/2004
Points 1971
|
18th August, 2010 at 09:02:50 -
DistanceAB = Sqr(((X("A")- X("B")) pow 2)+((Y("A")- Y("B")) pow 2))
The other formula, you would say:
+ Always
-> Moon: AngleFrom = AngleFrom + (360 / (2 * 3.142 * Distance / Speed))
-> Moon: X = X("Planet") + (Cos(AngleFrom("Moon")) * Distance)
-> Moon: Y = Y("Planet") - (Sin(AngleFrom("Moon")) * Distance)
All it really does is convert a linear speed into an angular speed - ie. If you want the moon to move a certain number of pixels around a planet, rather than a certain number of degrees.
Distance here is the distance of the moon from the planet that it is orbiting - ie. the radius of the circular orbit. It's a constant that you have to just pick yourself, rather than calculating it.
This is my new favourite formula:
Angle = Angle + max( min(((( ATan2( YA - YB, XB - XA ) - Angle + 540 ) mod 360 ) - 180 ), TurnRate ), -1 * TurnRate )
It rotates "A" towards "B", by up to "TurnRate" degrees - all in one line.
eg.
// Gradually rotate "Shooter" towards the mouse cursor.
+ Always
-> Shooter: Set Angle to: Angle( "Shooter" )+Max(Min((((ATan2(Y( "Shooter" )-YMouse, XMouse-X( "Shooter" ))-Angle( "Shooter" )+540) mod 360)-180), TurnRate( "Shooter" )), -1*TurnRate( "Shooter" ))
Edited by Sketchy
n/a
|
ELC_Games
Registered 30/11/2008
Points 17
|
18th August, 2010 at 17:32:40 -
Thanks for the advice Sketchy! I'll try that now.
Edited by ELC_Games
There are those who live to win, and those who win to live. There is no in between.
|
ELC_Games
Registered 30/11/2008
Points 17
|
18th August, 2010 at 17:51:24 -
Okay, now I've got the moon positioned the distance I want it from the planet, but I'm not sure how to make it orbit.
There are those who live to win, and those who win to live. There is no in between.
|
|
|