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.

Code Snippets / Projectile Physics code (DBPro)

Author
Message
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 21st Aug 2004 13:37 Edited at: 22nd Aug 2004 17:16
This code is a physics model for 3-D projectile motion. Suitable for anything which involves launching an object through the air, like a cannon ball, a golf-sim, a tennis game etc.......

You can alter pretty much every aspect of flight: - headwind/air-resistance/trailing wind, crosswind/hook/slice, lift due to backspin of the ball (like hitting a golf ball with a 9-iron), gravity, trajectory, initial velocity, and hardness of ground for affecting the amount of bounce.

Use the up and down arrow keys to alter trajectory, and the space key to launch the projectile. All other variables can be altered easily in the code.

Lost in Thought
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 22nd Aug 2004 13:37
Cool The falling seems a bit odd at higher wind resistances. When the object is accelerating the wind seems to push it back towards where it came from ok but wen it starts to fall it changes direction back to going forward again when it starts falling. Wouldn't the wind still be pushing back agaist it? Or am I misunderstanding this (which is very possible)?

MikeS
Retired Moderator
21
Years of Service
User Offline
Joined: 2nd Dec 2002
Location: United States
Posted: 22nd Aug 2004 15:19
Hey, this is another really great snippet. Anyone who's doing a scortched Earth remake should check this out, as it's perfect.

Nice job Ric.



A book? I hate book. Book is stupid.
(Formerly known as Yellow)
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 22nd Aug 2004 17:23
Quote: "The falling seems a bit odd at higher wind resistances"


Ah - well spotted Lost. It was acting wierd because I was using air resistance to do the job of headwind. As air resistance is actually proportional to ball speed, it's value drops when the ball gets slower - hence the apparent 'switching off' effect of the headwind.

I've changed it so there is now a seperate headwind variable hw# (which becomes a trailing wind if it's negative.) Now you can do proper boomerang stuff!!!

Ric.
Peter H
20
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 30th Aug 2004 06:37
nice...except my scorched earth re-make is in 2D

"We make the worst games in the universe."
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 6th Sep 2004 05:28
Should be pretty easily adapted into 2-d. Just reverse the y-values from positive to negative, set crosswind to zero, and use a sprite instead of an object.


Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 12th Sep 2004 07:36
Great work Ric.

- Merix

Athlon xp 2400+, 1.0GB Ram, Radeon 9800PRO 128mb

Login to post a reply

Server time is: 2024-11-23 19:38:44
Your offset time is: 2024-11-23 19:38:44