- Home /
constrain the player xz to a square and change controls on the points
Hi i currently need to constrain the players XZ to a square (or four splines) and a free y. this needs to use the movement control changes below ( it changes to match the side of the square.)
I've Tried to conform a object to a spline and constrain the player to that but i had issues when the player was stopped by a collider and the object could still move.
I've tried doing this with Colliders but its not precise enough. if anyone could point me in the correct direction that would be great.
front is (9,0,-7) (39,0,-7) right is (39,0,-7) ( 39,0,-35) back is (39,0,-35) (9,0,-35) left (9,0,-35) (9,0,-7)
void Move (float h, float v)
{
if (front) {
// Set the movement vector based on the axis input.
movement.Set (h, 0f, 0f);
movement = movement * speed * Time.deltaTime;
// Move the player to it's current position plus the movement.
playerRigidbody.MovePosition (transform.position + movement);
}
if (back){
// Set the movement vector based on the axis input.
movement.Set (-h, 0f, 0f);
movement = movement * speed * Time.deltaTime;
// Move the player to it's current position plus the movement.
playerRigidbody.MovePosition (transform.position + movement);
}
if (left){
// Set the movement vector based on the axis input.
movement.Set (0f, 0f, h);
movement = movement * speed * Time.deltaTime;
// Move the player to it's current position plus the movement.
playerRigidbody.MovePosition (transform.position + movement);
}
if (right){
// Set the movement vector based on the axis input.
movement.Set (0f, 0f, -h);
movement = movement * speed * Time.deltaTime;
// Move the player to it's current position plus the movement.
playerRigidbody.MovePosition (transform.position + movement);
}
Your answer
Follow this Question
Related Questions
Mouse Controlled object moving inside a circle. 2 Answers
constrain 2d gameobject to finger position (js) 1 Answer
Check if end of object reached. 1 Answer
How can I make my player 'stick' to a fixed object 1 Answer
Rotation Constrain 0 Answers