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 / [DBP] - 2D Trajectory Projectile w/Gravity and Wind Effects...

Author
Message
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 15th Jun 2011 17:16 Edited at: 15th Jun 2011 23:50
[EDIT]I could have sworn I clicked [GDK]... How do I change it?[/EDIT]


A fellow user has inquired about some 2D physics in action. Particularly regarding 2D Trajectory of shooting projectiles.

This snippet declares a Projectile class that handles Gravity and Wind effects during its traversal through space.

When running, click (and hold) the Left mouse to identify a starting point - marked by an "X", and drag the mouse. The position of the mouse when you *release* the mouse click determines the direction and velocity of the projectile.

Any angle between 0.000001f and 179.999999f will have gravity impact the shot in a negative manner (to help reflect boyancy(?)) of the projectile; whereas an angle between 180.0f and 360.0f will have gravity impact the shot in a positive (read: normal) manner.



I know it's a long snippet of code, but I believe it's very well commented and (hopefully) it will help others too...

Regards,
JTK

Edit: Fixed the href link...

Login to post a reply

Server time is: 2024-04-12 22:41:04
Your offset time is: 2024-04-12 22:41:04