Hi, i seem to be having a problem with moving a simple character left to right while on a slope. The character (A box at the moment) is a cube with a rigidbody as i'm wanting to use physics.
The character moves fine how it's supposed to on the flat (forward/backwards/left/right), but when i go on a bit of a slope and try to strafe (left/right) the character does move left/right but also moves backwards down the slope.
Heres the code that i'm using for controlling the character
var currentPosition : Vector3;
function Awake(){
//Get Start Position
currentPosition = transform.position;
}
function Update () {
if(Input.anyKey)
{
if(Input.GetKey(KeyCode.UpArrow))
transform.Translate(0,0,10 * Time.deltaTime);
if(Input.GetKey(KeyCode.DownArrow))
transform.Translate(0,0,-10 * Time.deltaTime);
if(Input.GetKey(KeyCode.LeftArrow))
transform.Translate(-10 * Time.deltaTime,0,0);
if(Input.GetKey(KeyCode.RightArrow))
transform.Translate(10 * Time.deltaTime,0,0);
currentPosition = transform.position;
}
//Stop from sliding down the slope
transform.position.x = currentPosition.x;
transform.position.z = currentPosition.z;
//Stop from falling over (Only temp)
transform.rotation.x = 0;
transform.rotation.y = 0;
transform.rotation.z = 0;
}
Any help on how to solve this would be greatly appreciated :)
Thanks, Shogun