How to find the ghost ball position in billiard game

It’s very important to find the position of ghost ball in billiard game, in this example showing how to use ray to find correct position for ghost ball in Unity3D development.

Create the game objects in Unity3D as below:

gameobjects

White ball with name:”Whiteball”, ghost ball with name:”GhostWhiteball” and some red balls with tag:”redball”. In order preventing disturbing to the ray by ghost ball, need to put ghost ball into “Ignore Raycast” layer.

layersetting

Add rigidbody for all balls except “ghost ball” and enable gravity.

Create a C# file named “controler.cs” and add it as component for main camera.

DEMO:http://wangweiqiang.net/demo/unity3d/ghostball/demo.html

 

The following two tabs change content below.
Wang Weiqiang is a senior web developer, and professional on ASP.NET, MVC, C#, Python, SQL Server, HTML5, Javascript, also interesting in machine learning and related algorithm.

Latest posts by Wang Weiqiang (王维强) (see all)

Wang Weiqiang is a senior web developer, and professional on ASP.NET, MVC, C#, Python, SQL Server, HTML5, Javascript, also interesting in machine learning and related algorithm.

Posted in Game Tagged with:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Categories

Recent Posts

Related Posts