- Home /
Cannot implicitly convert type `UnityEngine.Vector2' to `float'
Hello there, I am currently following the Unity Space Shooter video guide, and I am on Part 09. I am pretty much following the tutorial straight, except for the fact that I am doing it in 2D instead of 3D.
The error I am getting: "Assets/Scripts/RandomRotator.cs(9,29): error CS0029: Cannot implicitly convert type UnityEngine.Vector2' to
float'"
My problem is, that I am trying to create an asteroid, with a random rotation, by using rigidbody2D.angularVelocity = Random.insideUnitCircle * tumble;
Which is giving me an error, here is my entire script:
using UnityEngine;
using System.Collections;
public class RandomRotator : MonoBehaviour {
public float tumble;
void Start(){
rigidbody2D.angularVelocity = Random.insideUnitCircle * tumble;
}
}
Answer by robertbu · Feb 14, 2014 at 03:32 PM
Rigidbody2D.angularVelocity is a float since in 2D you only have one axis of rotation. So you can do something like:
rigidbody2D.angularVelocity = Random.vaule * tumble;
Also keep in mind that Rigidbody.angularVelocity is in Radians, and Rigidbody2D.angularVeclocity is in degrees, so you will need to adjust 'tumble' as appropriate.