# Find the right angle for certain distance with arc effect?

Hi,

i have read that to find a trajectory, we can use this equation with pointA and pointB (AB = distance) :

AB = v0^2 sin2a / gravity

i am looking only for the angle, as i will have a constant speed to throw the ball, so depending on the distance, how could i find the right angle?

but the function uses a different velocity compared to the angle, i would need to use the same velocity. So i would like to find the angle automatically when we have the distance, so that the ball can start coming down at the middle of pointA and pointB.

Is the equation above correct to find this in a 3d environment?

If so, i thought i could calculate it like this : sin2a = AB * g / v0^2
but then i am not quite sure how to go on to only find “a”, should i calculate the result of AB * g / v0^2 , then :

``````var distArc : float = Vector3.Distance(to.position, thisTransform.position);
var sin2a : float = (distArc * -1) / (speedArc*speedArc);
Debug.Log(Mathf.Asin(sin2a));
``````

and divide the total by 2?
The result in the Debug.Log is something like 0.2, 0.4, until it reaches the target (i only tested with a simple addForce in the forward direction), i am not sure if i am following a wrong way or not…

Thanks

So, this is not the best approach i think, but it kind of works, i used a characterController instead of a Rigidbody, and tell the ball to change its orientation comparing to the distance it has already made. If someone finds a good approach, he is welcome to share Hope this helps anyway :

``````function Start () {
thisTransform = GetComponent(Transform);
character = GetComponent(CharacterController);

distM = Vector3.Distance(cube.position, thisTransform.position);
startPoint = thisTransform.position;

//rotation to parallel
parallel = thisTransform.rotation;
parallel.eulerAngles = Vector3(0, 0, 0);
}

function Update () {
var dir : Vector3 = cube.position - thisTransform.position;
//if 1/3 of distM
if (Vector3.Distance(startPoint, thisTransform.position) > distM/3 ){
if (Vector3.Distance(startPoint, thisTransform.position) < distM/2){
//from 1/3 to middle
thisTransform.rotation = Quaternion.Slerp( thisTransform.rotation, parallel, Time.deltaTime  *speedRot );
} else {
//from middle to end
thisTransform.rotation = Quaternion.Slerp( thisTransform.rotation, Quaternion.LookRotation(dir), Time.deltaTime  *speedRot );
}
}

if (Input.GetAxis("Horizontal")>0) yes = true;
if (yes) {
character.Move(thisTransform.forward * Time.deltaTime  *30);
}
``````