Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / bit o physics

Author
Message
JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 14th Nov 2003 07:00
im making it so my guy can throw a grenade from his position p1x,p1y,p1z. but i dont know the physic equation
i actually found a example here http://darkbasic.thegamecreators.com/?m=forum_view&t=8874&b=10
but his download link is dead now.

Two words, moo.
Hell IVIonkey
22
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 14th Nov 2003 07:44
Here's a few things to get you started.

In parabolic (gravity) motion, the forward/back (X) and the up/down (Y) directions are independent of eachother.

If you throw something at force 5 at 60deg from the ground, you can use some simple trig to break down that vector into the X and Y components:
X-force = 5*COS(60) = 2.5
Y-force = 5*SIN(60) = 4.3301

Now, as long as the object remains in the air, it will move in the forward direction (X) every game itteration by some multiple of 2.5, but for simplicity we'll just say exactly 2.5. The object will move in the Y direction by the Y-force value, which initially is about 4.3301.

However, gravity constantly pulls on the object. The change in Y-velocity (or Y-force in this primitive example) is constant. On earth, it's -9.8meters/sec, but in game physics, you're best off making up a number. I usually use -.1 or so. Now, every game itteraion, modify your Y-velocity (or Y-force) by the gravity constant, in this example meaning subtract .1 from Y-force every game loop.

JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 14th Nov 2003 18:18
ok, thanx, this all looks good.
i will try putting that to code later today when i get home from school

Two words, moo.
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Nov 2003 22:14
For 3D:
d would be distance, or could be force. depends how you want to do it.

X2 = cos(angle)*d
p1y = sin(angle)*d

X = newxvalue(p1x,angle,X2)
Z = newzvalue(p1z,angle,X2)

position object grenade, p1x+X,p1y,p1z+Z

X and Z return coordinates based on an origin of 0,0,0. Therefore you need to offset the coordinates.
JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 15th Nov 2003 00:29
@Phaelax: can you explain that better? sorry, i dont quite understand

Two words, moo.
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 15th Nov 2003 05:20 Edited at: 15th Nov 2003 05:23
I did my best to document this little demo. Use mouse to look around, and arrow keys the move around. Left mouse button to throw the sphere.

These are standard physics equations of projectile motion.
x = v*cos(a)*t
y = v*sin(a)*t-0.5*G*t^2

JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 15th Nov 2003 19:24
that is awsome, thanx a ton!

Two words, moo.

Login to post a reply

Server time is: 2025-05-21 18:57:34
Your offset time is: 2025-05-21 18:57:34