Hello!
I’m trying to rotate my gameobject based on its velocity on the y-axis after zeroing it and applying a new force. But it always returns me 0. What am I doing wrong?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BirdController : MonoBehaviour {
private bool isDead = false;
private Rigidbody2D body;
void Start()
{
body = GetComponent<Rigidbody2D>();
}
void Update()
{
if (isDead == true)
return;
if (Input.GetMouseButtonDown(0)) {
if (GameController.instance.startGame == false) {
GameController.instance.startGame = true;
body.simulated = true;
}
body.velocity = Vector2.zero;
body.AddForce(new Vector2(0, 500));
print (body.velocity.y); // 0 :(
transform.rotation = Quaternion.Euler (0, 0, body.velocity.y * 3f);
}
}
void OnCollisionEnter2D()
{
isDead = true;
}
}