Hello everyone,
Am trying to make a simple pool game, and for the moment i don’t want to worry about projectile simulation to know where each ball will go, however, i still need to show some “line hints” to the player, and i thought i can easily doing it like this :
- cast a ray from the white ball position based on the desired direction of the “pool stick”
- if the ray hit another ball, then cast a new ray from the hit point toward the center of this ball
This should be pretty straight forward but for some reason am getting this as a result :
but what i need is this :
The code am using is this :
void CheckForHits ()
{
Vector3 fwd = transform.TransformDirection (new Vector3 (Vector3.left.x, Vector3.left.y + 270, Vector3.left.z));
//+270 because the pool stick is because i need to invert the line cause am hiting the ball from behind
RaycastHit objectHit;
if (Physics.Raycast (transform.position, fwd, out objectHit, 50)) {
if (objectHit.collider.name.Contains ("ball")) {
Debug.DrawRay (objectHit.point, objectHit.collider.transform.position, Color.green);
}
}
}
Thank you