Convert UnityEngine.Vector3 to float [SOLVED]

Script:

function Update () 
{
var distance = rigidbody.velocity * 2;
Camera.main.orthographicSize = distance;
}

Error:Assets/Scripts/Bubble.js(56,32): BCE0022: Cannot convert 'UnityEngine.Vector3' to 'float'.

How could i solve this problem?

var distance = rigidbody.velocity * 2;

this returns a Vector3. But orthographicSize is a float variable.
So you could use something like distance.x

But what exactly do you want to achieve?

You can use rigidbody.velocity.magnitude for what you want. Because rigidbody.velocity represents velocity as a 3 dimension vector(as in physics) but magnitude is the velocity in the sense we use in common life.

1 Like

That when the object moves faster the camera zooms out.

Thanks, that worked perfectly !!! :wink: