Ok so i know this has been answered before and i know its simple game math and i thought i had the right function (FromToRotation) but it just keeps going in one direction and i cant figure out what math im looking for, so i apologize
I want to fire a projectile from my player to wherever on the ground i clicked. I am able to Instantiate the projectile and make it move in a fixed direction but i cannot seem to figure out how to angle the projectile to face the intersect point on the ground and move towards it. I know where the intersect point is as well, just not the math to do the rest
if(Input.GetMouseButtonDown(0)){
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;
var didHit : boolean = Physics.Raycast(ray, hit);
//var cursor = GameObject.Find(currentCursor.name);
if(didHit) {
var angle = Quaternion.FromToRotation(shootFrom.transform.position, hit.point);
var spell = Instantiate(prefab, shootFrom.transform.position, angle);
spell.rigidbody.AddForce(transform.right * shootSpeed);
}
}
I tried to determine the angle but it doesn’t seem to work. What am i doing wrong?