Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: LogLady on April 17, 2015, 05:22:50 PM

Title: Snooker / billiards / pool ball direction
Post by: LogLady on April 17, 2015, 05:22:50 PM
Hello!

I'm trying to trace the direction that a ball will do before I shoot it just like you see on snooker games. This is a exact example of what I want to accomplish:
Any help is appreciated.

Thanks!
Title: Re: Snooker / billiards / pool ball direction
Post by: inyourbus on April 19, 2015, 08:18:30 AM
Could you do a raycast, then when the ray hits the wall or ball raycast again with reflection from the hit position and so on...

Then draw a line using line renderer.

Thats my best guess.
Title: Re: Snooker / billiards / pool ball direction
Post by: LogLady on April 23, 2015, 09:48:05 AM
Using the draw line action I got it working right for the first ray but I couldn't cast the second ray to the right direction. I positioned an object at the point the first ray hit but the ray is not pointing to the direction that the ball do when shot. Maybe I'm doing wrong using the Vector3 operator Reflect where I use the origin of the first ray as the first vector3 and the hit point of the ray as the second vector3. The result gives values higher than the game area.

Any help is appreciated!
Title: Re: Snooker / billiards / pool ball direction
Post by: Lane on April 23, 2015, 10:01:31 AM
This is a tricky thing to do, I think. I don't really have a solution since it would require a decent bit of tinkering with trial and error but the first thing I did think about was the need for a Spherecast rather than a Raycast.

Raycasts have no width but the balls are going to collide at the tanget point rather than the center, where the raycast is going... So it will make all of the reflected vectors incorrect in terms of the actual physics results. Plus, all of the other factors like friction, rotational torque, cushion flexibility etc are all not going to be accounted for so the reflections might be close, but not accurate.
Title: Re: Snooker / billiards / pool ball direction
Post by: LogLady on April 23, 2015, 11:56:00 AM
As close as a snooker game like Side Pocket would be great  :D .
I'm not making a snooker it is just for debug purposes, not actual gameplay.

Sadly the Spherecast actions on the Ecosystem give less resources than the Raycast function as to store the hit position and the object hit by the ray but it is the first time I'm using the spherecast so maybe I'm doing something wrong or expecting.

Lane, could you please clarify it a bit more?
Title: Re: Snooker / billiards / pool ball direction
Post by: LogLady on June 08, 2015, 02:23:22 PM
Thanks for your great help, inyourbus !  :)