Realize Gunshot-Physics

Post your questions, suggestions and experiences regarding to Image manipulation, 3d modeling and level editing for the Irrlicht engine here.
Post Reply
Konstantin
Posts: 12
Joined: Fri May 18, 2007 3:06 pm
Location: Panketal, Germany

Realize Gunshot-Physics

Post by Konstantin »

Hi,
I've absolutely no idea how to realize a gunshot from the center of the screen with variable speed, range, power and accuracy. Would you tell me your ideas please?!? :cry:

Thanks for your answers!
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

You can use irrlicht's ray versus node bounding box test, which will return the node hit if it gets shot by a ray, you can generate the rays using code in irrlicht's tutorial 7.
http://irrlicht.sourceforge.net/docu/cl ... nager.html

Then when you get the node you can use conservation of momentumn to model the physics:

Before collision(bullet velosity*bullet mass)+(node hit velsoity*node hit mass)=after collision(bullet velosity*bullet mass)+(node hit velsoity*node hit mass)

After a collsion we expect the bullet velocity to be 0, therefore you rearrange the equation to find the node's velcity after the collision.

final node hit velosity=((bullet velocity*bullet mass)+(node hit velcoity*node hit mass))/nodehit mass;

Add this velocity every frame to the node that got hit, however you get friction in realy life so scale down the velcoity after each frame;

so every time you update a node you should:

nodeposition+=velcoity;
velocity*=(time of collision - current time)*0.5 (change the 0.5 for more friction);

you can get the times from device->getTimer()->getTime();, store the results in a double or f64;

some people use impluses but this way i easier.

To simulate diffrent power's you can change bullet mass for bigger projectiles, bullet speeds for diffrent types of guns. As for accuracy you can get the distance of the node that gets hit and use then reduce bullet speed in the momentum equation.
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
Post Reply