View Full Version : pixel perfect aiming
05-08-2003, 08:21 PM
in one day i feel like ive gotten a lot done on my first ever fps (second game all together) so far i can move around in my world with mouselook and strafe, and peek... so im done with the moving code, and i want to go onto shooting...
(its gonna be a paintball game) http://www.opengl.org/discussion_boards/ubb/wink.gif
and i have no idea how i would do that...
i already made the sprite for the splat of the paintball, but how exactly would i calculate where that sprite would end up,....
any good tutorials?
You could use the old f = ma equation to determine the tragetory of the "paint blob"
Then check when it collides...like all other objects in your game. You can resolve it collision position from its last velocity and obstacle position.
Oh yeah all those are vectors BTW.
05-09-2003, 04:31 PM
To put a splat on a 3D world is quite advanced really. There are several ways to do it. It's generally known as applying decals, like in counterstrike or quake.
here is what I would do.
1) use a line-of-sight algorithm, or also called ray-casting. Fire a ray from your gun position. Find the first point of intersection in the world.
2) From there, create a sphere of influence, to get the geometry near the point of intersection (basically, the radius of the splat).
3) Calculate the texture coordinates at the vertices on that geometry, using the distance from the point of intersection (to fade the texture as the points get more distant), and your gun orientation matrix.
4) Save the calucaltions in a list tiny model.
5)Render all the geometry fragments together, with the splat textures, and with a polygon offset, so it gets rendered slightly in front of the walls and the models.
6) if you don't want to do a line of sight test (using an infinite ray), use bullet physics, where the paintball travels between updates (you know Pos = Pos + Velocity * dt, ect...). Model the bullet collision as a segment, from the position it started from the previous frame, to the position it should be at the next frame. Find the first intersetion with the world geometry and that segment, and apply the calculations from 2) to 6).
I'd personnaly use the bullet physics, where you can apply gravity and air friction (to slow the bullet down).
[This message has been edited by oliii (edited 05-09-2003).]
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.