NaN error for Mathf.Asin

Hello-

I keep getting a NaN error for certain variables(ph3, angleradians, and angle) in this script. I suspect the reason is that because both ph3 and angle are linked to angleradians, they cannot calculate the answer. Angleradians uses Mathf.Asin, but I cannot find what I did wrong. Any ideas?

#pragma strict

var shell:GameObject;
var self:GameObject;
var distance:float;
var ph1:float;
var ph2:float;
var ph3:float;
var angleradians:float;
var velocity = 240;
var angle:float;
var target:Transform;

function Update(){
	distance = Vector3.Distance(target.position,transform.position);
//-----------------------------------------------------------------------
	ph1 = distance*9.81;
	ph2 = ph1/velocity;
	angleradians = Mathf.Asin(ph2);
	ph3 = angleradians * 3.14;
	angle = ph3/180;
	var currentrot = self.transform.rotation.x;
	var requiredangle:float;
	var requiredrot = currentrot - angle;
	self.transform.eulerAngles.x = requiredangle;
	Instantiate (shell, self.transform.position, self.transform.rotation);
}

although I’m sure you are aware that
to convert to degrees you use
AngleInRad*(180/pi)

angleradians = Mathf.Asin(ph2);
ph3 = angleradians * 3.14;
angle = ph3/180;

Should be

angleradians = Mathf.Asin(ph2);
ph3 = angleradians * 180;
angle = ph3/Mathf.PI;

Assuming you want ‘angle’ to be in degrees.

It looks like you are doing :

Degrees = Rads * (PI/180) which is incorrect. It could be sending your degrees based functions right out. You are converting To Radians not From Radians

Whenever velocity is zero, it causes a divide-by-zero error for ph2, resulting in a NaN for any variable that uses ph2.