Skip to main content
GameDev.net gamedev.net
🔒 Locked

throwing something in a arche patern

Started by Anddos Sep 1, 2012 at 12:23 PM 2 replies 1.4k views
Original Post
Anddos
Anddos
I want to make grenade in my fps game, how do you make it go outwards in a arche...
:)
Jason Z
Jason Z
It is typically done by using a rigid body dynamics simulation with either a physics engine, or possibly just a simplification of those equations.
Jason Zink :: DirectX MVP   Direct3D 11 engine on CodePlex: Hieroglyph 3 Direct3D Books: 
TomKQT
TomKQT
The arch trajectory is incredibly simple to programm (*), but things get MUCH more complicated when you want the grenade to properly collide with other static or even moving objects in your scene and bounce on contact. Then you really need some kind of physics engine (albeit a very simple one).

[size=2](*) All you need is your initial velocity vector v (magnitude = how strongly you throw; orientation = which direction and under what angle you throw), initial position vector p (the grenade position in the player's hand) and a constant gravity acceleration vector g. Then each frame you just update the velocity and position vectors:
v += g * dt
p += v * dt
where dt is the time span between frames and the operations are vector operations.
Bacterius
Bacterius

(*) All you need is your initial velocity vector v (magnitude = how strongly you throw; orientation = which direction and under what angle you throw), initial position vector p (the grenade position in the player's hand) and a constant gravity acceleration vector g. Then each frame you just update the velocity and position vectors:
v += g * dt
p += v * dt
where dt is the time span between frames and the operations are vector operations.

[s]Gravity only affects the vertical component of velocity.[/s] Haha sorry my bad, I thought you defined g as a scalar. I must be tired - mods feel free to delete this post.
“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.