public Transform target;
public float shootForce = 200f;
private void FixedUpdate()
{
Vector3 initialDirection = target.position - transform.position;
float initialHorizontalDistance = new Vector3(initialDirection.x, 0f, initialDirection.z).magnitude;
float timeOfFlight = initialHorizontalDistance / shootForce;
float verticalVelocity = initialDirection.y / timeOfFlight + 0.5f * Mathf.Abs(Physics.gravity.y) * timeOfFlight;
Vector3 initialVelocity = new Vector3(initialDirection.x, verticalVelocity, initialDirection.z).normalized * shootForce;
Vector3 targetFuturePosition = target.position + target.GetComponent<Rigidbody>().velocity * timeOfFlight;
Vector3 adjustedDirection = targetFuturePosition - transform.position;
float adjustedHorizontalDistance = new Vector3(adjustedDirection.x, 0f, adjustedDirection.z).magnitude;
float adjustedTimeOfFlight = adjustedHorizontalDistance / shootForce;
float adjustedVerticalVelocity = adjustedDirection.y / adjustedTimeOfFlight + 0.5f * Mathf.Abs(Physics.gravity.y) * adjustedTimeOfFlight;
Vector3 adjustedInitialVelocity = new Vector3(adjustedDirection.x, adjustedVerticalVelocity, adjustedDirection.z).normalized * shootForce;
float horizontalAngle = Mathf.Atan2(adjustedDirection.x, adjustedDirection.z) * Mathf.Rad2Deg;
float verticalAngle = Mathf.Asin(adjustedVerticalVelocity / shootForce) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(-verticalAngle, horizontalAngle, 0f);
}
here is my code, i am kinda having am problem aiming up and down