How to check the character is falling after jumping , 2D - C#
Hey everybody! Im new to unity , I used this c# code to rotate the character(45 ) , if it goes up(when using space button ) and after that goes down and rotate (-45) , but it doesn't work well ! do you know what should i change ? when it start to rotate , it doesn't stop ! using UnityEngine; using System.Collections;
public class Player : MonoBehaviour {
public Vector2 jumpForce = new Vector2(0,300);
bool isFalling;
bool playerFalling;
bool jumped;
void Update () {
if (Input.GetKeyUp ("space")) {
jumped = true;
rigidbody2D.velocity = Vector2.zero;
rigidbody2D.AddForce (jumpForce);
if (rigidbody2D.velocity.y > -0.1 && isFalling == false ) {
transform.Rotate (0, Time.deltaTime * 45, 45, Space.World);
}
}
if (rigidbody2D.velocity.y < -0.1 && jumped) {
isFalling = true;
transform.Rotate (0, Time.deltaTime * (-45), (-45), Space.World);
}
Comment
Your answer
