![]() |
Trigonometry Tango!
1 Attachment(s)
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: |
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 |
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. |
Quote:
|
Quote:
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. |
Quote:
|
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. |
Quote:
But I guess it's about what's most comfortable and familiar to the scripter, and examining multiple approaches is a good exercise. |
Quote:
To be fair though, i'd probably do it with forces if I was to go and script it right now. |
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! |
Quote:
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. |
Quote:
|
Okay, so I've figured out the distance and the angle
NPC Code: 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. |
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.
|
Quote:
|
| All times are GMT +2. The time now is 03:10 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.