Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by oliver-jones · Nov 12, 2013 at 10:35 AM · reflectionaimpool

Pool Game (Billiards) - Reflection

Hello,

I'm trying to implement an aiming system into my pool game like this:

alt text

I've got it working, it fires a raycast from the ball, to the direction, and then a reflection is fired from that. The issue I'm having is that my ball doesn't actually follow the raycast. It's not very accurate.

I think this is because the balls are actually being moved by the Unity Physics and Rigidbody Force. How can I take this into account for my aiming system?

 function Update () {
 
     //Initial Direction
     var direction = transform.TransformDirection(Vector3.forward);
     var hit : RaycastHit;
     if (Physics.Raycast (transform.position, direction, hit, Mathf.Infinity)){
         Debug.DrawLine (transform.position, hit.point, Color.red);
 
         //Reflection
         var reflectDir = Vector3.Reflect(direction, hit.normal);
         reflectDir.x = reflectDir.x * offset;
         var hitReflec : RaycastHit;
 
         if(Physics.Raycast (hit.point, reflectDir, hitReflec, Mathf.Infinity)){
             Debug.DrawLine(hit.point, hitReflec.point, Color.green);
         }
     }
 
 
     if(Input.GetButtonDown("Fire1")){
 
         rigidbody.AddForce(transform.TransformDirection(Vector3.forward) * initialForce, ForceMode.Impulse);
     }
 }

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fafase · Nov 12, 2013 at 11:05 AM 0
Share

How bad is it not following? Compared to the picture you show, do you get a totally different path?

Fact is, the real path will depend on where you exactly hit the white ball with the stick. The given path is the one you get if tapping exactly in the middle of the sphere with no friction.

Then there is the torque due to rotation, this one will make it harder I guess to predict the exact path.

So in order to get a more accurate but not 100%, you would have to get the hit point of the stick to the ball and define the raycast from there taking consideration of the torque. Since I do not know where to start with this, I 'm sorry I'm oot (Dragon's den style).

avatar image oliver-jones · Nov 12, 2013 at 11:13 AM 0
Share

The cue doesn't actually hit the pool ball, it just applies force to the general forward direction of the ball. The aim system isn't completely inaccurate, but just enough not to rely on it.

Thanks

avatar image TimBorquez · Nov 12, 2013 at 03:16 PM 0
Share

can you just move the ball to each point yourself and gradually slow it down ins$$anonymous$$d of using the physics?

5 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by PaulzCreative · Jun 16, 2015 at 10:51 AM

One thing to consider heavily when creating systems like this is Unity's realistic ability to account for friction.

For example: Executing that shot on a real pool table, it would be near impossible to replicate the path shown in your diagram.

Here's why ( Given: cue ball is hit dead center no additional SIDE OR TOP spin is introduced ):

Pool table rails (very bouncy rubber covered with cloth) will impart friction on a ball. ALSO, the rubber is somewhat soft which means the ball will PUSH or sink into the rubber in an amount directly proportional to the velocity of the ball. Which means MORE FRICTION is imparted. This is why the harder you hit a ball into a rail on a pool table, the tighter the rebound angle.

Those two factors influence the friction imparted (especially to a multi rail shot) In pool, this is called ROLLING ENGLISH. This means that every rail collision adds side spin (on Y Axis). So when that ball hits another rail that spin will influence the rebound angle - effectively widening the angle.

SO... If I were a betting man, based on the diagram supplied, I would wager that your ball hit the third rail CLOSER to the upper right corner pocket, and very likely scratched in the lower left corner pocket with enough speed.

Hope that helps!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by tellemstevedave · May 23, 2014 at 06:54 PM

I had this issue until I changed the physics material in default physics settings to an actual material that had no friction.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by shashank_gargeshwari · Apr 29, 2016 at 07:38 PM

@oliver-jones This is because of the bounciness of the physics materials of the side rails and the ball. Set both to one to follow line exactly. To slow down ball, use some sort of deceleration function. Hope this helps. :D

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Fran-Matsusaka · Feb 22, 2017 at 10:25 AM

@oliver-jones I know that the anwser is pretty old but... Maybe the innacurace comes from the raycast and not the ball itself. Ball has a radius, but raycast not, is just a single point searching for collision. Different volume objects will get different results. To get an accurate bounce with Raycast use Spherecast instead, and provide the ball rigidbody radius to get expected results.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Moligon · Apr 27, 2021 at 12:35 AM

i was having the same problem and what a did was create a slow down every time that the object collide simulating the bounciness velocity reduction.

void OnCollisionEnter(Collision col) { if (col.gameObject.name == "GolfTableWall") { rb.velocity = rb.velocity * 0.5f; }

but you have to keep in 1 the bounciness of the matirial so the angle after thebounciness will be the same as the raycast.

be carefull with the Bounce Combine mode.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Law of Reflection and pool ball 0 Answers

Bouncy material and walls 1 Answer

Is there any way to cut down the performance costs on reflective and refractive planes? 1 Answer

Creating realistic glass 4 Answers

Reflection Ignore Unsupported Properties 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges