I need some help to get it right.
I did some research and managed to get something done, but it isn’t work how it should.
I use a second ball to give the basketball force , angle … aldonaletto script. I have some line renderer working but not how it is supposed to be. So if anyoane can help me that will be great.
I have another plane who let me move the invisible ball up and down not only left and right. The prediction won’t work in some positions(I get this error:rigidbody.velocity assign attempt for ‘ball(Clone)’ is not valid. Input velocity is { NaN, NaN, NaN }.
UnityEngine.Rigidbody:set_velocity(Vector3)
Force:Update() (at Assets/Scripts/Force.cs:98) ) and my ball don’t follow the path everytime. If i want to hit the floor and then bounce to the hoop , first it make some sort of an arc then go to the ground and nothing else.

``````	void Update()
{
if(Input.GetKey(KeyCode.Escape))
{
}

var referenceForward = Vector3.up;
var referenceRight= Vector3.Cross(Vector3.up, referenceForward);
var newDirection = ball2.transform.position - playerFire.transform.position;
var angle = Vector3.Angle(newDirection, referenceForward);
unghi = angle;

//		Distances = Vector3.Distance(Input.mousePosition, new Vector3(ball2.transform.position.x, ball2.transform.position.y, 0));

if(Input.GetButton ("Fire1"))
{
//path simulation
//			simulatePath();
mousePoz = new Vector2 (Input.mousePosition.x, Input.mousePosition.y);

if(mousePoz != Vector2.zero)
{
ray = Camera.mainCamera.ScreenPointToRay(mousePoz);

if(Physics.Raycast(ray, out hit, Mathf.Infinity))
{
ball2.transform.position = new Vector3(hit.point.x, hit.point.y, 0);
}
}
}

if(Input.GetButtonUp("Fire1"))
{
rigidbody.useGravity = true;
rigidbody.velocity = BallisticVel(myTarget, shootAngle);
}
}

Vector3 BallisticVel(Transform target, float angle)
{
Vector3 direction = transform.position - target.position; // get target direction
float 	height = direction.y; // get height difference
direction.y = 0; //retain only the horizontal direction;
float	distance = direction.magnitude; // get horizontal distance;
direction.y = distance * Mathf.Tan(a); //set direction to the elevation angle;
distance += height / Mathf.Tan(a); //correct for small height difference
// calculate the velocity magnitude
float velocity = Mathf.Sqrt(distance * Physics.gravity.magnitude / Mathf.Sin(2 * a));
return velocity * direction.normalized;
}
``````

Here it is my update function and Ballistic.
Now the simulation path function :

``````//	void simulatePath()
//	{
//		Vector3[] segments = new Vector3[segmentCount];
//		segments[0] = playerFire.transform.position;
//		Vector3 segVelocity;
//
//		Vector3 direction = transform.position - ball2.transform.position; // get target direction
//		float 	height = direction.y; // get height difference
//		direction.y = 0; //retain only the horizontal direction;
//		float	distance = direction.magnitude; // get horizontal distance;
//		direction.y = distance * Mathf.Tan(a); //set direction to the elevation angle;
//		distance += height / Mathf.Tan(a); //correct for small height difference
//		// calculate the velocity magnitude
//		float velocity = Mathf.Sqrt(distance * Physics.gravity.magnitude / Mathf.Sin(2 * a));
//		segVelocity = velocity * direction.normalized;
//
//		for(int i = 1;i < segmentCount; i++)
//		{
//
//			if(segments *!= ball2.transform.position)*
``````

// {
// float segTime = (segVelocity.sqrMagnitude != 0) ? segmentScale / segVelocity.magnitude : 0;
// segVelocity = segVelocity + Physics.gravity * segTime;
// RaycastHit hit;
// *
// if(Physics.Raycast(segments[i-1], segVelocity, out hit, segmentScale))
// {
// segments = segments[i-1] + segVelocity.normalized * hit.distance;
// segVelocity = segVelocity - Physics.gravity * (segmentScale - hit.distance) / segVelocity.magnitude;
_
// segVelocity = Vector3.Reflect(segVelocity, hit.normal);_
_
// }_
_
// else*_
// {
// segments = segments[i-1] + segVelocity * segTime;
// }
// }
*// *
// }
// Color startColor = playerFire.nextColor;
// Color endColor = startColor;
// startColor.a = 1;
// endColor.a = 0;
// sightline.SetColors(startColor, endColor);
*// *
// sightline.SetVertexCount(segmentCount);
// for(int i=0; i < segmentCount; i++)
// sightline.SetPosition(i, segments*);*
// }
i use only x and y but the ball after it been launched can bounce anyware