View Single Post
  #7  
Old 03-14-2005, 03:07 AM
Polo Polo is offline
Classic Systems Admin
Join Date: Sep 2002
Location: Vancouver, Canada
Posts: 735
Polo is on a distinguished road
Send a message via AIM to Polo
As an alternative to the (very correct and very good) force based method Kai is suggesting, we can create 'pretty much' the same effect in a different way.

Theres 2 things we need to consider. The angle between the player and the vortex, and the distance away the player is.

We can work out the distance by using Pythagoras Theorem...

√(δx^2 + δy^2) = distance,
where δx is the horizontal difference,
and δy the vertical difference.

Next we need to work out the angle... this can be down with the arctan() function.

arctan(δx/δy) = distance,
where δx is the horizontal difference,
and δy the vertical difference.

Now... this will only give us a result between -pi/2 and pi/2 radians (-90 and +90 degrees), and so the first half and second half of our 'circle' of motion will wield the same result. We can compare whether or not δx and δy are positive or negative, and work out which quadrant (quarter) of the full circle the player is in. We can then add on pi or so to get the correct angle we want for all of the circle...
(Graal does however provides a function to do all the angle calculation for you - I'll leave it up to you to find it.)

Now that we have both the angle and the distance we can do some manipulation...

To create the spiral vortex type motion, we need to add some value to the angle, and decrease the distance. Im sure you can work out how to do that .

Now we have to convert the distance and angle back into a new δx, δy. We can turn the angle back into a component x/y by using sin(angle) and cos(angle). the results these give are the ammount of x and ammount of y we would have if the distance were 1... however the distance is not 1. Simple solution.. simply multiply by our newly calculated distance.

new-δx = distance*cos(angle)
new-δy = distance*sin(angle)

You may need to adjust those (ie: add a negative factor to one of them, or switch cos for sin in both... it depends how you got the angle and how you visualize it n stuff), but all the maths is there for you.

Hope you understood all that.
__________________
Be good little players, or Master Storm will ban you!



Proof that the staff are crazy..
*Ghost Pirate: I'm a little teacup short and stubbe here is my raygun here is my butt
DragonX: Jumping jack rabbits Batman! Our eggo waffles have been stolen! To the batmobile Robin!
X-Mann (RC): I have a head ache
Reply With Quote