Hey guys,
Here’s what I am attempting: I wish to change the direction my character faces on the horizontal axis. I figured I could accomplish this by “If” statement with “Input.GetKeyDown” and then change the scale of my object on the x axis to be -1 or 1 depending on the direction I wish my character to face. Obviously, I can’t seem to get it to work.
Here is what I have at the moment.
var speed : float = 6.0;
var gravity : float = 20.0;
private var velocity : Vector3 = Vector3.zero;
function Update() {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded)
{
velocity = Vector3(Input.GetAxis( "Horizontal" ), 0, Input.GetAxis( "Vertical" ));
velocity = transform.TransformDirection(velocity);
velocity *= speed;
}
if (Input.GetKeyDown("a")
{
transform.localScale.x = -1;
}
if (Input.GetKeyDown("d")
{
transform.localScale.x = 1;
}
velocity.y -= gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
}
Any help would be greatly appreciated! Taken babysteps here.