• Advertisement
Sign in to follow this  

Targeting reticle

This topic is 4339 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm making a 3rd person view game, where you control a tank. In the middle of the screen, there's the targeting reticle like this: And I also have the exact position of where the shot is coming out of the turret. My problem is how can I make it to shoot in the position where the target reticle is? How can I find the resulting direction vector that the shot should use to go in the direction of the reticle?

Share this post


Link to post
Share on other sites
Advertisement
do a line collision test through the frustum. the linesegment starts at the reticle position on the front of the frustum and it ends at the reticle position on the back of the frustum. whatever it collides with, you aim the turret/shoot the bullet in that direction of the collision point.

-me

Share this post


Link to post
Share on other sites
Thanks for this reply, now I have one option.
However, what if the player aims at the sky? And if there's no SkyBox/SkyDome to perform the collision?
Would aiming only at the far plane of the frustum be enough?

Thanks for the help

Share this post


Link to post
Share on other sites
Yes it would, if you didn't understand what he meant here is a picture

Camera *

|
X|
Tank Turrent --> |
|

Projected Camera Reticle Ray Y*


The X Spot is where the tank should aim to hit the object the camera is looking at. (The Y Spot is where the camera hits the farplane, and in this case is where the turret must not aim()

Besides for ray tracing you could also use glUnproject.

Basically glUnproject takes a screen x,y coordinate and gives you the world coordinates for this. Ofcourse you need to do this test before rendering your sprites and stuff.

One problem with this view(3rd person) is aiming at small objects, if the ray or unproject misses the object the tank's turret could rotate to a much further spot. for exmple the Y on picture^^

Share this post


Link to post
Share on other sites
I've been thinking about it (haven't implemented yet), and I thought I would do the checks on this order:

1) Project the ray, and check against the OBB of every visible object (enemies/buildings)
2) If step 1 doesn't work, check against the terrain
3) If step 2 doesn't work, check against the skybox

However, I haven't thought about the ray missing the object and ending aiming in the wrong direction... I'll have to implement and test it too see how it will behave.

Thanks for the help.

If there's anyone else who would like to say something about this, feel free to do it.

Share this post


Link to post
Share on other sites
How about simply reading back the cursor position from the depth map?

Works like a charm, and if there's no skydome, it will simply return the value of the far clipping plane. :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Rasmadrak
How about simply reading back the cursor position from the depth map?

Works like a charm, and if there's no skydome, it will simply return the value of the far clipping plane. :)


glUnproject takes a screen x,y coordinate and gives you the world coordinates for this. Ofcourse you need to do this test before rendering your sprites and stuff.

What I mean is that you should render all solid geometery first, get the coordinates using glUnproject and then render the rest. I do it on my RTS and it works excellent, best of all I don't need to worry about triangle-ray collisions and stuff.

You are faced with a problem though, consider if the reticle is on glass. Is the player aiming at the glass or what is behind it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement