1
\$\begingroup\$

I have a basic Unity project on GitHub.

Basically, I have a Cuestick that aims and shoots using the mouse. You can rotate around the cueball with your mouse and when you're ready to shoot, you can hold down the right mouse button and move the mouse forward. The game came follows the cuetip.

However, the collision between the cuestick and cueball is wonky. The cuestick protrudes through the ball and only pushes the ball forward only a little bit.

I've created rigid bodies and colliders for both cuestick and cueball. I've set the cuestick's rigid body to kinematic (if it's unchecked, the poolstick will barely dent the ball). I've tried using OnCollisionEnter and a Debug.Log statement to no avail.

Any help would greatly be appreciated. You can find my scripts in /GameLogic (they're F# sharp scripts whose binaries get compiled and outputted into the /assets folder).

\$\endgroup\$
  • 1
    \$\begingroup\$ How are you moving the pool cue? Are you imparting velocities/impulses to it, or manually positioning it via its transform? If it's the latter, then to the physics engine it may appear that it's teleported into the ball, with no particular forward momentum to transfer, so it just resolves the penetration by the smallest displacement/velocity change that it can. \$\endgroup\$ – DMGregory Sep 21 '16 at 2:49
  • \$\begingroup\$ Additionally if you do use AddForce() make sure that you set the masses of each object to sensible values. \$\endgroup\$ – Draco18s no longer trusts SE May 10 '17 at 13:35
1
\$\begingroup\$

Why using a complicated collision detection algorithm? Just calculate the distance from the center of the ball to the end of the cuestick. If it's less than or equal to the ball's radius, the cuestick is colliding with the ball.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ I would venture to guess that he wants a decent collision algorithm to model complete rigid body physics. Just detecting a collision like this wouldn't include things like velocity, jerk, spin, acceleration, etc... \$\endgroup\$ – dannuic Apr 25 '16 at 17:13
  • \$\begingroup\$ This collision model will easily produce the hit point and normal vectors required to do everything you explained. It is even analytically correct if a cylinder were used instead of a point to represent the stick. \$\endgroup\$ – MickLH Apr 25 '16 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.