Hello,
Im trying to flip my character 180 degrees when the S key is pressed. Ive tried all kinds of things to make this happen and searched a million posts and Im still stuck. So heres my code I hope someone can help.
Quick Note: I have 2 camera set up one is a main camera top down view and a second camera (which is what Im looking through to see the character to rotate.
Ive tried:
transform.rotation = Quaternion.LookRotation(-transform.forward);
But it has some weird results. So onto the code:
var speed :float = 12;
var robotController :CharacterController;
function Start ()
{
robotController = GetComponent(CharacterController);
//set all animations to loop
animation.wrapMode = WrapMode.Loop;
//except shooting
animation["shooting1hand"].wrapMode = WrapMode.Once;
animation["idleTap"].wrapMode = WrapMode.Once;
//Put idle and run into lower layers (the default layer is always 0)
//Since Shooting is in a higher layer, the animation will replace idle/run
animation["shooting1hand"].layer = 1;
//Stop animations that are playing (in case user forgot to disable play automatically)
animation.Stop();
}
function Update ()
{
var forward = transform.TransformDirection(Vector3.forward); //move forward
var curSpeed = speed * Input.GetAxis("Vertical");
robotController.SimpleMove(forward * curSpeed);
//forward animation
if (Input.GetAxis("Vertical") > 0.2)
{
animation["run"].speed = 1;
animation.CrossFade("run");
}
else
animation.CrossFade ("idleTap");
//reverse animation
if(Input.GetAxis("Vertical") < -0.2)
{
//animation["run"].speed = -1;
animation.CrossFade("run");
//ROTATE The Character 180 if the S key is Clicked
}
//Shoot
if(Input.GetButton("Fire1"))
animation.CrossFade("shooting1hand");
}
anyhelp would be awesome.