• Advertisement
Sign in to follow this  

Allowing player to shoot?

This topic is 3594 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

I've been working on an FPS type game and I want to give the player the ability to shoot at enemies. From browsing these forums, it looks like picking is the way to do this. Is the term picking specific to mesh picking, or is there another type that better suites this type of functionality? I've been messing with unproject but haven't been able to get the behavior I want. I'm wondering if I'm going down the right path or wasting time on the wrong thing.

Share this post


Link to post
Share on other sites
Advertisement
Unproject is only part of the problem. Once you've managed to project your vector from screen space to world space, you will need to perform a ray-mesh collision check, where the ray will be along this newly acquired vector.

Share this post


Link to post
Share on other sites
There are a lot of posts discussing D3DXIntersect in this forum, which is probably what you're looking for. Use the Search function for the forum in the upper right-hand corner.

Share this post


Link to post
Share on other sites
It depends on how you want the shooting to occur. Do you want the player to aim a crosshair at the center of his view at the target, or do you want the player to move the mouse freely (without changing the view) and click on a target? In either case, generally speaking, you would use ray picking. The origin of the ray in the former case would just always be the center of the screen. If you have the position of your player and you know his orientation, just cast a ray from that position along that orientation. This ray will "hit" whatever is in the center of your current view (where the crosshair is).

Ray picking in general terms is just following a ray until you intersect "something" in space. It could be a mesh, a plane, a triangle, as you get into the details. There are some D3DX routines that help with this (D3DXIntersectMesh or D3DXMeshIntersect I believe, or something similar) if you are testing against a D3DXBaseMesh type. In theory, you would determine if the ray hits the plane that the triangle is in (determine the point on the plane) and then determine if that point lies within the bounds of the triangle.

Don't forget to test all meshes in front of you and keep track of the closest one to you.

Share this post


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

  • Advertisement