- Home /
Make a cube rotate exactly 90 degrees rather than keeping it rotating
I am very new to unit.I am trying to make a geometry dash like game but cant seem to make the cube rotate 90 degrees when jumping.It either keeps rotating or it rotate 8 degrees.Any response would be helpful but if you can put a not so complicated code would be even more welcomed.
UPDATE : I made it rotate but for some reason it rotates once to the left and then then next jump it rotates to the right
// using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour {
bool isGrounded = false;
public float jumpForce;
public Rigidbody2D rb;
public GameObject player;
public GameObject sprite;
public float speed = 55f;
public float rotation = 0f;
private Quaternion qTo;
void Start() {
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
if (player.transform.position.x < -7.1)
{
Destroy(player);
}
if (isGrounded == false)
{
qTo = Quaternion.Euler(0, 0, rotation);
sprite.transform.rotation = Quaternion.Slerp(sprite.transform.rotation, qTo, 0.15f);
}
}
void FixedUpdate()
{
if (Input.GetKey(KeyCode.Space))
if (isGrounded == true)
{
rb.velocity = new Vector2(0, jumpForce * rb.mass * rb.gravityScale);
}
}
void OnCollisionEnter2D(Collision2D other)
{
if (other.collider.tag == "Ground")
isGrounded = true;
}
void OnCollisionStay2D(Collision2D other)
{
if (other.collider.tag == "Ground")
{
isGrounded = true;
}
}
void OnCollisionExit2D(Collision2D other)
{
if (other.collider.tag == "Ground")
{
isGrounded = false;
}
if (Input.GetKey(KeyCode.Space))
{
rotation -= 90f;
}
}
}
Your answer
Follow this Question
Related Questions
Float value = gameobject.rotation 2 Answers
How can I make player rotation control camera's x rotation and mouse control it's y rotation? 1 Answer
Getting the rotation of raycast target object and applying to the player (noob question) 1 Answer
How would i track rotational direction from my rotation cordinates? 1 Answer
angular velocity only on one axis 1 Answer