Jump to content
  • Advertisement
Sign in to follow this  

Confusing ray mesh collision problem

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

Hello, I'm new here and I'm new to directX. I've been looking into building a FPS engine and I'm trying to make the player walk up a ramp as explained in this thread here: http://www.gamedev.net/community/forums/topic.asp?topic_id=428882&whichpage=1� The player class houses a camera and a ray starting at the current location of the camera and pointing downwards:
    public Vector3 FeetRay
      get { return Camera.Position; }
    public Vector3 FeetRayDirection
      get {return _feetRayDirection;} //(0,-1,0);
The idea is that when this ray hits something that is closer that the height of the player, the player is elevated so that the camera remains a constant height above whatever is directly underneath. So, when the player moves the following method is called:
    public bool CheckCollision(cGordon gordon)

      gordon.FeetRay.Unproject(DXDevice.Viewport, DXDevice.Transform.Projection, gordon.Camera.View, mapWorldMatrix);

      gordon.FeetRayDirection.Unproject(DXDevice.Viewport, DXDevice.Transform.Projection, gordon.Camera.View, mapWorldMatrix);


      IntersectInformation info = new IntersectInformation();

      return MapMesh.Intersect(gordon.FeetRay, gordon.FeetRayDirection, ref info)

but the Intersect test returns false unless the camera happens to be over a particular square - which is not over (0,0,0) - and I'm starting to get a bit frustrated. I'm guessing the problem is due to the Matrix being passed to the Unproject method. I understand that both the mesh and the ray have to be transformed so that they are both in the same space right? So the ray position is relative to the cameras position which is in world space anyway and the mapWorldMatrix variable is the same variable that the device was given just before the mapMesh was drawn, which was Matrix.Scaling(100, 100, 100) * Matrix.Translation(0, 0, 0); Any help would be greatly appreciated. Thanks

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!