Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-14-2005, 02:13 AM
Deek2 Deek2 is offline
Registered User
Join Date: May 2002
Location: Springfield, Missouri
Posts: 1,578
Deek2 is on a distinguished road
Trigonometry Tango!

Hello,
I have recently been interested in developing a script that uses an attractive gravitational force that spins nearby players towards yourself in a vortex spiral direction. I am merely interested in the mathematical concepts/equations relevant to achieve this. I would prefer to work out the nuts and bolts by myself, since I am inexperienced in the gscript language.
Oh, woe! If only I weren't mathematically inept (I haven't even started Geometry yet!).
Observe this visual aid:
Attached Thumbnails
Click image for larger version

Name:	weeeeeee.png
Views:	231
Size:	6.7 KB
ID:	31335  
Reply With Quote
  #2  
Old 03-14-2005, 02:32 AM
Evil_Trunks Evil_Trunks is offline
Evil
Evil_Trunks's Avatar
Join Date: Dec 2004
Posts: 391
Evil_Trunks is on a distinguished road
if such a thing existed on classic we would probably deem it a "spiral vortex"

im having a hard time breaking down the math it uses, it doesn't do a "realistic" pull however
__________________


Last edited by Evil_Trunks; 03-14-2005 at 02:43 AM..
Reply With Quote
  #3  
Old 03-14-2005, 02:37 AM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Depends on the nature of the pull. You'll need to calculate some kind of force to be exerted on the objects, probably proportional to the object's mass and inversely proportional to the square of the distance to the centre. Then use a simple F=ma to determine the acceleration and add it to the object's velocity.

Again and again and again.
__________________
Reply With Quote
  #4  
Old 03-14-2005, 02:52 AM
Deek2 Deek2 is offline
Registered User
Join Date: May 2002
Location: Springfield, Missouri
Posts: 1,578
Deek2 is on a distinguished road
Quote:
Originally Posted by Kaimetsu
Depends on the nature of the pull. You'll need to calculate some kind of force to be exerted on the objects, probably proportional to the object's mass and inversely proportional to the square of the distance to the centre. Then use a simple F=ma to determine the acceleration and add it to the object's velocity.

Again and again and again.
I'm not quite sure how one would represent a player's mass on gscript.
Reply With Quote
  #5  
Old 03-14-2005, 03:01 AM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Quote:
Originally Posted by Deek2
I'm not quite sure how one would represent a player's mass on gscript.
Think of a number. That's the player's mass.

Any units are fine. It just has to be consistent throughout the universe. As long as the ratios are intact (ie, chairs weigh less than houses, etc), you're okay.
__________________
Reply With Quote
  #6  
Old 03-14-2005, 03:06 AM
Zero Hour Zero Hour is offline
Stiff Upper Lip
Zero Hour's Avatar
Join Date: Oct 2006
Location: Nova Scotia, Canada
Posts: 0
Zero Hour is on a distinguished road
Send a message via AIM to Zero Hour
Quote:
Originally Posted by Kaimetsu
Think of a number. That's the player's mass.

Any units are fine. It just has to be consistent throughout the universe. As long as the ratios are intact (ie, chairs weigh less than houses, etc), you're okay.
That's a pretty neat idea, would give the vortex some detail [:
__________________
Reply With Quote
  #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
  #8  
Old 03-14-2005, 03:17 AM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Quote:
Originally Posted by 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
Well, trigonometry works, but it's less efficient and actually more complicated, so I'm not sure if it's advisable. Plus, if you wanted to incorporate other forces (like if the player is trying to move) or produce non-circular orbits, you'd need to maintain independent velocities anyway.

But I guess it's about what's most comfortable and familiar to the scripter, and examining multiple approaches is a good exercise.
__________________
Reply With Quote
  #9  
Old 03-14-2005, 03:24 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
Quote:
Originally Posted by Kaimetsu
Well, trigonometry works, but it's less efficient and actually more complicated, so I'm not sure if it's advisable. Plus, if you wanted to incorporate other forces (like if the player is trying to move) or produce non-circular orbits, you'd need to maintain independent velocities anyway.

But I guess it's about what's most comfortable and familiar to the scripter, and examining multiple approaches is a good exercise.
Yeah, you cant get the same kind of accuracy thats true, but then I dont think people would really notice the difference. I decided to post it as (in the UK) you cover pythagoras and trigonometry long before the concept forces (in mathematics) and stuff during you education... so I thought it may seem more 'accessible' to those who have covered less mathematics.

To be fair though, i'd probably do it with forces if I was to go and script it right now.
__________________
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
  #10  
Old 03-14-2005, 03:26 AM
Deek2 Deek2 is offline
Registered User
Join Date: May 2002
Location: Springfield, Missouri
Posts: 1,578
Deek2 is on a distinguished road
What needs to be stated is that players that are farther away from the vortex's epicenter will need to have a greater mass than someone who is closer. Since the vortex's focal point will be my current coordinates, players who are closer to me will hypothetically weigh less than the players that are farther away, hence the gravitational pull and force applied to these players will be much greater. I'm just thinking out loud.
I believe I can find a way to attribute these mass quantities to the relevant players, but I'm still trying to comprehend these math equations, only having the knowledge of algebra and the scripting experience of two weeks, this makes for quite a formidable challenge!
Reply With Quote
  #11  
Old 03-14-2005, 03:36 AM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Quote:
Originally Posted by Deek2
Since the vortex's focal point will be my current coordinates, players who are closer to me will hypothetically weigh less than the players that are farther away, hence the gravitational pull and force applied to these players will be much greater
O_o

It's not possibly to alter the mass of an object without turning it into multiple objects. If you want the force to increase when the player is nearer, simply make it inversely proportional to the square of the distance, as I said before.
__________________
Reply With Quote
  #12  
Old 03-14-2005, 03:38 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
Quote:
Originally Posted by Deek2
...players who are closer to me will hypothetically weigh less than the players that are farther away, hence the gravitational pull and force applied to these players will be much greater.
This is what Kai referred to as 'inverse square'. Basically this just means that thos twice as far away, will have half the pull. The formula for calculating this 'theoretical mass' is mass/(distance^2).
__________________
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
  #13  
Old 03-14-2005, 05:05 AM
Deek2 Deek2 is offline
Registered User
Join Date: May 2002
Location: Springfield, Missouri
Posts: 1,578
Deek2 is on a distinguished road
Okay, so I've figured out the distance and the angle
NPC Code:
for (this.p=0;this.p<playerscount;this.p++){
this.distance=((playerx-players[this.p].x)^2 + (playery-players[this.p].y^2))^.5;
this.angle=arctan((playerx-players[this.p].x)/(playery-players[this.p].y^2));
}


Or at least I think.
The difficulty I'm encountering now is how to actually use the variables that I created. I don't know how to even figure out which certain quadrants the players fall into.
Reply With Quote
  #14  
Old 03-14-2005, 06:15 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
The player is eithe above or below, and to the left or right... that 4 quadrants. However, like i said before, Graal has a function for getting angles that will handle this for you.
__________________
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
  #15  
Old 03-14-2005, 06:56 AM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
Quote:
Originally Posted by Polo
This is what Kai referred to as 'inverse square'. Basically this just means that thos twice as far away, will have half the pull.
Twice as far has a quarter the gravitational force
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:33 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.