Skip to content

Instantly share code, notes, and snippets.

@benloong
Created January 29, 2013 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benloong/4661336 to your computer and use it in GitHub Desktop.
Save benloong/4661336 to your computer and use it in GitHub Desktop.
using using UnityEngine;
using System.Collections;
using System.Collections.Generic;
class MathHelper {
float static CalcAngleOfElevation (Vector3 from, Vector3 to, float v, float g) {
float x = (to - from).z;
float y = (to - from).y;
float v2 = v * v;
float v4 = v2 * v2;
float fac = v4 - g*(g*x*x + 2*y*v2);
if(fac < 0) {
return Mathf.Infinity;
}
float theta = -Mathf.Atan((v2-Mathf.Sqrt(fac))/(g*x)) * Mathf.Rad2Deg;
while(theta < 0) theta += 360f;
return theta;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment