- Home /
Third person movement similar to Max Payne
Hey everyone!
So basically, I am having a bit of trouble getting the movement in my game to work the way I want it. I am trying to create a basic game with movement similar to Max Payne for a side project. The game is similar to Max Payne in that you can walk forwards in the direction the camera is pointing, but you can also walk forwards while aiming left or right, by holding the A or D key to move relative to the rotation of the camera, so it is sort of like strafing, but a bit different.
I hope this makes some sense, but here are some screenshots of the kind of behavior I'm looking for:
This is an example of walking forwards.
And here is an example of walking forwards, whilst aiming in a different direction.
In the case of the second image, I would be holding the A key (or left arrow or whatever it is bound to) so that I am moving to the left of the screen, but I would be aiming to the right of my character, even though that is the center of the screen.
At the moment I am always moving in relation to world space, so that is how I can capture these screenshots, but I have attempted to use transform.TransformDirection to get the desired result, and I can move forward, backward, left and right, except I cannot aim in a different direction, as my entire player character rotates if I move the mouse.
NOTE: I am using C# for scripting.
I am still fairly new to C#, but I should be able to handle most concepts, as I have experience in a few other programming languages, including C++.
I hope this is enough information, and absolutely any help would be greatly appreciated!
Thanks,
Evan.
If all you want to do is rotate the lower half of the body, make a script with a Transform variable that holds the lower body parent transform. Then grab the motion component (whatever motion input script you're using) and therefore the vector that the player is moving along. After that it's just a simple Quaternion.LookRotation
Hey $$anonymous$$$$anonymous$$$$anonymous$$xJOEY1, thanks for your comment man!
So, I ended up using a simple transform.LookAt method I found elsewhere that only rotates on the y-axis, which works pretty well. The only real problem I have left is that I want to make the player only rotate when he is moving, because with my current method he rotates if I look around when idle.
For the rotation now, I have made a really newbie "if" statement that checks if Input.GetAxis("Horizontal") is greater than or less than 0.1, and the same for the Vertical axis and then calls the transform.LookAt. I'm not sure why, but the character still rotates even when stationary.
I think I may be messing up the less than and greater than signs and somehow making it only rotate between -0.1 and 0.1 or something, I don't know :P
Here's an example:
float v = Input.GetAxis("Vertical");
float h = Input.GetAxis("Horizontal");
if (v > 0.3 || v < 0.3 || h > 0.3 || h < 0.3) {
transform.LookAt(targetPosition);
}
I'm using FinalI$$anonymous$$ for the ai$$anonymous$$g of the gun, so that is how I basically move the upper-half of the character without the lower half, and it is working great.
Thanks again for your comment!
[Edit]
I can't believe I missed the negative signs!
I fixed that now, and it works great!
Is there a better method than this dodgy if statement?
Answer by FakedMeerkat · Jul 01, 2014 at 01:05 AM
I made a bit of progress by adapting the Third Person Input script from the new sample assets, and it lets me move in the desired fashion, but I cannot figure out how to rotate my player's lower body to face forwards when moving forwards.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Loading a new level from a previous one. 1 Answer
Make player not be seen by AI, when player in foilage and shadows. 1 Answer
Starting out C# help 2 Answers