- Home /
How to stop 3rd Person Contoller from moving diagonally?
Greetings, I would like to know how to stop my player from moving diagonally and just have the player move forewards, backwards, left, and right. Does anyone here know how to do so?
Answer by Montraydavis · Oct 30, 2012 at 04:35 PM
It probably has something to do with your movement script!
It should look something like this:
function Update() {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) {
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}
No, it isn't a problem. I need it to ONLY move Left right forewards and backwards. I don't want it to be ABLE to move diagonally.
So I need someone to edit the movement script so that the player is only allowed to go in 4 directions.
Answer by Akraz · Nov 30, 2012 at 12:56 AM
I am having a similar problem, albeit with addForces. Did you ever find a solution to this?
Your answer
Follow this Question
Related Questions
How to make player only go in 4 directions? 1 Answer
How to move a player to a certain point? 0 Answers
2D Movement Problems 2 Answers
RTS Controller? 0 Answers
Need help getting my character to move 2 Answers