- Home /
Character Rotation on the Touch of a Button
Sorry I wasn't specific enough. What I wanted was my character to do a backflip on the touch of a button. Only when grounded equals true. Here is my script. I have already made an input for backflip. Its positive button is left alt. PS I'm very new to scripting.
var moveSpeed = 3.0;
var turnSpeed = 3.0;
var jumpSpeed = 35.0;
private var grounded : boolean = false;
//Standard Moving Actions
function Update ()
{ var controller : CharacterController = GetComponent(CharacterController);
transform.Rotate(0, Input.GetAxis ("Horizontal") * turnSpeed, 0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = moveSpeed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
if(Input.GetButtonDown("Jump"))
{
transform.position+= transform.up * jumpSpeed * Time.deltaTime;
}
}
//In Air Actions
if(Input.GetButtonDown("Jump"))
{
grounded = true;
}
@script RequireComponent(CharacterController)
Is there a question in there? Assu$$anonymous$$g you intend to ask about rotating. You can rotate with transform.Rotate, transform.RotateAround, transform.eulerAngles, transform.localEulerAngles, transform.Rotation. and/or transform.localRotation. If using a rigidbody, you can also use rigidbody.$$anonymous$$oveRotation, rigidbody.AddTorque, rigidbody.AddRelativeTorque, rigidbody.AddForceAtPosition, and/or rigidbody.rotation. To rotate when grounded is true, put your rotation inside if(grounded){}. If you want something specific to the code you're using, you might consider posting that code.
Answer by lodendsg · Jan 25, 2021 at 11:32 AM
This requires more explination than I think fits well in a forum
https://learn.unity.com/tutorial/controlling-animation
This Unity learn section should get you going though. It talks about setting up and controlling your animator and as I recall it uses an example of jumping. It does get into the scripting aspect as well