Members - Reputation: 111
Posted 17 December 2012 - 12:45 PM
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
Members - Reputation: 157
Posted 18 December 2012 - 12:57 AM
this is a queit question for everyone..
I saw same quesiton at graphics section..
Hmm to find where I click on 3D space.
you must check what point I click on view frustum's near plane and far plane.
if you know 4 corner point or near plane you can assume where is my mouse.
Match screen to near plane. screen position is like 0~ 1024 but near plane is come from actual position ..
Hmm... It's too simple
plz give me more question for understanding..It's not easy at first step
Beauty is only skin deep , ugly goes to bones
World's only 3D engine tunner and 3D engine guru.
and real genius inventor but very kind warm heart .. and having serious depression for suffering in Korea
www.polygonart.co.kr ( currently out dated and only Korean will change to English and new stuff when I get better condition sorry for that)
Crossbones+ - Reputation: 780
Members - Reputation: 111
Posted 18 December 2012 - 09:24 AM
Members - Reputation: 449
Posted 18 December 2012 - 06:18 PM
In simpler words, try something like this:
Game1.Instance.ModelManager.addModel("Arrow", (ModelPosition + new Vector3(0, 40, 0)), Vector3.Normalize(farPoint-(ModelPosition+new Vector3(0,40,0)*2.0f)));