(In C#/XNA.) I mean, I can't find an answer nowhere. I'm trying to learn how to make a Third Person Shooter, especially like the one I found in a game called "M.A.R.S.", from Epic Games. I don't want to remake that game, I just want to understand how the Third Person works.
There, the screen aims to a direction, has a crosshair and its center stays right next to the player, slightly above the shoulder. And the player aims to that same direction the screen aims, pointing to that.
What I don't understand is how the bullets the player shoot go to that direction if the player is not aiming from the same position the camera is (or is it?).
For now, in my game, I can only select things that are in front of the player, having his own View Direction (a Vector3) which follows camera's WorldMatrix.Forward and applying a Ray from the player to that direction. So if I change the direction of the camera, the player will select things in front of him, following the camera direction.
And it doesn't work to be a shooter, because if I put a crosshair in the center of the screen, the player won't shoot there but to his own front.
Thanks for any help. I'm still searching, but even here I couldn't find what I want yet.
EDIT: what I found in this link is how to make the Ray cast come out from the camera. But how much should I rotate the character's view direction so its Ray goes to the same point the camera's one goes? So the Rays make something like this: /|.
EDIT 2: Now I'm testing some code. The closest way I created until now is this.
Game.ActiveCamera.FollowPosition = Player.Position; Game.ActiveCamera.FollowReference.Y = Player.Race.Height * 0.5f; Vector3 target = Player.Position; target.Y += Game.ActiveCamera.FollowReference.Y; target += (Player.ViewDirection * Game.ActiveCamera.FarPlaneDistance); //if (Game.Input.KeyHeld(Keys.F2)) // Game.ActiveCamera.Target = Game.ActiveCamera.Position + Game.ActiveCamera.WorldMatrix.Forward; //else Game.ActiveCamera.Target = target; //MathConverter.Convert(Player.Character.Body.Position + Player.Character.ViewDirection * 10);
I use a chasing camera that follows the FollowPosition. It has an Offset with X and Z, and I change Y to stay right above the character's shoulder.
Then the camera's target, which is the problem, I'm using the Player's Position plus its Forward (ViewDirection) times the camera's FarPlaneDistance, so the camera aims far away to the same point the character aims.
But I still don't know if the bullets are going to respect the crosshair on the screen this way.