- Home /
How to make a 2d object back flip when a key is pressed
So im making a game where you have to jump over obstacles that come at you. But i want to include a option where you can backflip when pressing the Q key. The script I have makes the character flip a very tiny bit but not all the way. i have to keep pressing the key for it to flip
here is my script: using UnityEngine; using System.Collections;
public class Flip : MonoBehaviour {
public float myRotationSpeed = 100.0f;
public bool isRotateZ = false;
private bool positiveRotation = false;
private int posOrNeg = 1;
void Start ()
{
GetComponent<Collider>().isTrigger = true;
if(positiveRotation == false)
{
posOrNeg = -1;
}
}
void Update ()
{
if (Input.GetKeyDown (KeyCode.Q)) {
if (isRotateZ) {
transform.Rotate (0, 0, myRotationSpeed * Time.deltaTime * posOrNeg);//rotates coin on Z axis
}
}
}
}
never$$anonymous$$d, i figured it out. All i did was change if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Q)) { to: if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.Q)) {
Your answer
Follow this Question
Related Questions
Shooter 2D - Problem with rotation of bullet to face direction (velocity) 2 Answers
Slow Sprite Rotation Toward Movement Direction - Top-Down 2D Game 0 Answers
How to flip 2d character walk movement? 3 Answers
My player is not rotating upwards when it moves upwards. Any advice? 1 Answer
Brick Breaker - Ball not bouncing back from the brick. 2 Answers