I am making this 3rd person shooting game in which there is a player and enemies in the 3D world and I want to shoot arrows at the enemies.What I want is to control the cross hair of the player via the mouse.The problem is mapping mouse coordinates to 3D world.Now I am well aware of the popular picking code at MSDN forum but that is for the First Person Camera.Mine is a Chase camera(the camera is positioned at some offset behind the player).I cant seem to understand how to give the proper direction and initial position of arrow so far I have used this but it fails.
Vector3 farSource = new Vector3(Mouse.GetState().X, Mouse.GetState().Y, 1);
Vector3 farPoint = Game1.Instance.GraphicsDevice.Viewport.Unproject(farSource, camera.Projection, camera.View, Matrix.Identity);
Game1.Instance.ModelManager.addModel("Arrow", (ModelPosition + new Vector3(0, 40, 0)), Vector3.Normalize(farPoint-Vector3.Normalize(ModelPosition+new Vector3(0,40,0)))*2.0f);
Basically what I am trying to do is when the user presses right click on the mouse, a model of arrow is added to the 3D world whose initial position is that of player position plus some offset(so that shot is fired from the centre of player) and the direction is determined by subtracting far point from player position and then normalizing it.This is not working because shots are very offset from original mouse position.Please help.Thank you
neogeocgMember Since 29 Oct 2012
Offline Last Active Dec 19 2012 05:21 AM