Hi, I got a problem when doing on my project (kind of billiard game)

assume I have a two ball with different mass. I want the second Ball move on my Target direction using collision forces when collide with first ball. so I create a Target Point containing a vector data which the first ball move on. the target Point of course it has to slight off from the Second ball Center of Mass.

now this is my question… How much it (the Target Point) is far from second ball’s center of mass (assuming both of it has different radius and mass).

here’s how I did it :

void Launch(Vector3 dir, Vector3 dir2){
//first ball is handling this script
//dir is Position of Second Ball
//dir2 is Position of Second Ball has to heading at during collision

//get Angles
float ang = Vec2Angle (new Vector2 (dir.x, dir.z), new Vector2 (transform.localPosition.x, transform.localPosition.z));
float ang2 = Vec2Angle (new Vector2 (dir.x, dir.z), new Vector2 (dir2.x, dir2.z));

//Get Angle direction of Second Ball heading at
float deltaAngle=Mathf.Abs (Mathf.DeltaAngle (ang, ang2))
//Because we need to target it into Opposite angle...
deltaAngle += 180;
//get relative position
Vector3 rPos= dir2 - dir;
//determine Target Position offset <- THE PROBLEM
float offset= Mathf.Sin(deltaAngle*Mathf.Deg2Rad);
rPos=rPos.normalized * Mathf.Lerp(0.3f,0.6f,offset); //0.3 is the second ball Radius

//Now add it into our Rigidbody Velocity
dir+=rPos;
GetComponent<Rigidbody>().velocity=(dir-transform.localPosition).normalized*40;
}

public static float Vec2Angle (Vector2 dir, Vector2 pivot)
{
Vector2 s = dir - pivot;
if (s.x > 0)
	return Vector2.Angle (Vector2.up, s);
else
	return 360 - Vector2.Angle (Vector2.up, s);
}

the current code isn’t work properly (it slightly off from my targeted direction).

if you have questions about this, just ask. I’m really appreciate for your time here.

Distance = ball1 radius + ball two Rafius

Create a Ray with origin ball two, direction - target direction so it’s opposite direction.

Use Ray.getpoint(distance) to get the point to aim the moving ball one at.

Mass doesn’t matter per say, like it effects where the balls end up after imPact but

not if they do unless you under shoot