# shooting a sphere from (x1, y1, z1) to (x2, y2, z2)

I’m making a game like Battle Ship. I want to shoot a sphere from a known point (x1, y1, z1) to another known point (x2, y2, z2). I’m trying to do so using Parabola’s mathematical equations, but it’s so complicated. Can any one help me with this? is there any other way to do this using Rigidbody (or maybe something else)?

There are 2 ways about doing this. You could “fake it” using a simple Bezier algorithm. I would recommend using unity’s rigidbody. Set angular drag and drag to 0, so you can simulate free fall without that fake air resistance.

Using simple physics to calculate the velocity based off of angle you give it, you can achieve your goal.

``````    public Transform targetPosition;
public GameObject projectile;
public float Angle = 45;

void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
GameObject ball = (GameObject)Instantiate(projectile, transform.position, Quaternion.identity);
ball.GetComponent<Rigidbody>().velocity = CalculateVelocity(targetPosition, Angle);
Destroy(ball, 10);
}
}
public Vector3 CalculateVelocity(Transform target, float angle)
{
var dir = target.position - transform.position;
var h = dir.y;
dir.y = 0;
var dist = dir.magnitude;
var a = angle * Mathf.Deg2Rad;
dir.y = dist * Mathf.Tan(a);
dist += h / Mathf.Tan(a);
var vel = Mathf.Sqrt(dist * Physics.gravity.magnitude / Mathf.Sin(2 * a));
return vel * dir.normalized;
}
``````