Sign in to follow this  
homer_3

Allowing player to shoot?

Recommended Posts

homer_3    173
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
Omid Ghavami    1007
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
Buckeye    10747
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
Supernat02    604
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this