Accurate cross hairs

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
lazerblade
Posts: 194
Joined: Thu Mar 18, 2010 3:31 am
Contact:

Accurate cross hairs

Post by lazerblade »

Lot's of 3d game have them, too many want them. The objective is quite simple, create accurate cross hairs and draw them on the HUD. It may sound easy, but there is something I don't quite get.

Let's say I draw the cross hairs in the center of the screen as one pixel. I then line up the gun to face the center of the player's line of sight. This is no problem for things like handguns where ray-tracing can be used. But for a rocket launcher for example, things can get a bit icky. The rocket will only strike on the cross hairs if one of two scenarios occur. Either the rocket launcher being Perfectly lined up with the camera, or the player being the exact right distance from the object being struck.

This poses a problem which I have seen solved in many FPS and other games, but have failed to solve myself. How do you get accurate cross hairs for a projectile weapon like a rocket launcher?

I'm all ears. :mrgreen:
LazerBlade

When your mind is racing, make sure it's not racing in a circle.

3d game engine: http://sites.google.com/site/lazerbladegames/home/ray3d
lazerBlade blog: http://lazerbladegames.blogspot.com/
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post by shadowslair »

Try to:
1) cast a ray from camera origin towards 0,0,1 (towards the crosshair)
2) get the penetration point (if any)
3) your weapon-towards-target-dir will be the normalized(penetrPoint - weaponTipPosition); or sth alike.
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
lazerblade
Posts: 194
Joined: Thu Mar 18, 2010 3:31 am
Contact:

Post by lazerblade »

So the rotation of the gun would be changed to face the cross hairs collision point based on ray tracing? True you could change the projectile's direction, but that might occasionally lead to unrealistic flight paths. Probably a compromise would be best.

Thx! :D
LazerBlade

When your mind is racing, make sure it's not racing in a circle.

3d game engine: http://sites.google.com/site/lazerbladegames/home/ray3d
lazerBlade blog: http://lazerbladegames.blogspot.com/
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

I solved this by casting a ray from the crosshair, and seeing where it hits. Then the projectile travels from the gun to the hit point. It can create clipping in a few instance, but it's almost never noticeable.
lazerblade
Posts: 194
Joined: Thu Mar 18, 2010 3:31 am
Contact:

Post by lazerblade »

Sounds good, and looks like what I see happening in MechWarrior 4 based on the projectile overshooting the cross hairs if the target has moved. ;)
LazerBlade

When your mind is racing, make sure it's not racing in a circle.

3d game engine: http://sites.google.com/site/lazerbladegames/home/ray3d
lazerBlade blog: http://lazerbladegames.blogspot.com/
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post by shadowslair »

lazerblade wrote:So the rotation of the gun would be changed to face the cross hairs collision point based on ray tracing? True you could change the projectile's direction, but that might occasionally lead to unrealistic flight paths. Probably a compromise would be best.
Rotating the gun will be ugly- if you aim with the rocket launcher standing in front of a wall it may rotate that much, so it`ll cover almost the whole screen. You just shoot the projectile in the direction you get. Ducky does absolutely the same, and as he says- the clipping is minimal and somewhat what you want, plus it`s probably the best way to do it.
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
lazerblade
Posts: 194
Joined: Thu Mar 18, 2010 3:31 am
Contact:

Post by lazerblade »

Agreed.
LazerBlade

When your mind is racing, make sure it's not racing in a circle.

3d game engine: http://sites.google.com/site/lazerbladegames/home/ray3d
lazerBlade blog: http://lazerbladegames.blogspot.com/
Post Reply