6

I'm trying to calculate what angle to hit a pool ball and predict where ball will go to.. I thought target ball should move within a normal direction.. but it moves on totally different direction

RaycastHit2D hit = Physics2D.CircleCast(cue.position, _radius, dir, 100f, ~(ignoreLayer));
if (hit.collider != null)
{
    Debug.DrawRay(hit.collider.transform.position, -1f * hit.normal, 
    Color.green, Time.fixedDeltaTime);
}

Here is result:

enter image description here

Set velocity

rb.velocity = dir * force;

Result:

enter image description here

How to find exact move direction, Thanks

Edit:

I have tried Double Radius Casting this works only half way.. only when ray inside inner circle

wrRios
  • 104
  • 6
  • Set velocity to hit.normal * force? – Fredrik Widerberg Jun 16 '18 at 10:01
  • we can set this for target ball OnCollisionEnter2D, manually change targeting ball velocity.. but this is kind of cheating..) I think(hopefully) there are move intuitive way to achieve this.. thanks @FredrikWiderberg – wrRios Jun 16 '18 at 11:09
  • It is dependent on a number of properties, including i) the (ratio of) masses of the balls, ii) the coefficient of resistution between the balls (1 = elastic collision), iii) friction between the balls (which leads to angular momentum transfer) and iv) whether you take spin into account (as a direct result of iii)) – meowgoesthedog Jun 16 '18 at 15:17
  • did u set the physics material on the balls to zero friction and zero bounciness? – Lincoln Cheng Jun 19 '18 at 04:41
  • @LincolnC Yes also I have tried to set everything to zero, keep default settings and many more.. – wrRios Jun 19 '18 at 05:22
  • Anyone please.. With double radius We can predict 100% only when ray is inside ball.. but direction still wrong when on casting outside http://prntscr.com/jwp62v – wrRios Jun 19 '18 at 12:02
  • Anyone please.. – wrRios Nov 26 '18 at 09:15
  • If you don't mind sharing all your C# scripts and screenshots of your Unity project settings, I can try it out myself. Between the two, there are so many variables that you might need to share a little more of your project to make the issue reproducible. – K Man Jan 27 '19 at 13:20
  • In newer versions of Unity you can apparently use multiple Physics Scenes to precisely determine the outcome. Take [this video](https://www.youtube.com/watch?v=DcGiUcfLbes) of drawing the trajectory of a ball, for instance. – Philipp Lenssen Aug 06 '19 at 10:40
  • heres one old test project also, i think it worked fine there https://github.com/unitycoder/Snooker2D – mgear Feb 16 '21 at 08:19

1 Answers1

0

I suppose this is just a limitation of the physics engine, which is optimized for speed and use in games, and is not so exact.

Trying this myself in a simple 2D scene, I found that if I set the friction to 0.01 and the bounciness to 1.0, it works the way I would expect. (in Unity 2020.1)

In the small sample scene I added, there is a ball aiming at another so that the resulting angle should be 45 degrees. And after setting the phyics-mat to the properties with friction 0.01 and bounciness 1.0, the resulting angle is as expected.

With the default-mat I get the same behaviour you described.

Did you forget to assign the physics materials?

Have you single-stepped to the point of contact and checked if the aiming is correct?

my sample project trying this

Blindleistung
  • 672
  • 8
  • 21