Search Unity

Golf Ball Bounce

Discussion in 'Scripting' started by caseyboundless, Apr 13, 2016.

  1. caseyboundless

    caseyboundless

    Joined:
    Oct 17, 2011
    Posts:
    590
    What's the best way to code my golf ball bouncing off hard surfaces when I'm using
    Code (CSharp):
    1. golfBall.AddForce(playerTransform.forward * ballSpeed * Time.deltaTime * 1000);
    At the moment I'm just using the phys materials and rigidbody components on the ball for the bounce. The bounce looks very stale. Any ideas on what to try? Thanks.
     
  2. Iron-Warrior

    Iron-Warrior

    Joined:
    Nov 3, 2009
    Posts:
    838
    First off, I'm guessing your AddForce line is intended to be the "shot" force, which happens once when the ball is fired. For forces that are added only on a single frame, you don't need to multiply by deltaTime. As well, you'll want to use ForceMode.Impulse. So instead use:

    Code (csharp):
    1. golfBall.AddForce(playerTransform.forward * ballSpeed, ForceMode.Impulse);
    Second off, how big is the ball? Golf balls are ~50 mm in diameter. Unity's units don't revolve around any set system, but gravity is set to -9.81, which means really big objects look like they're falling slowly.
     
  3. caseyboundless

    caseyboundless

    Joined:
    Oct 17, 2011
    Posts:
    590
    I have the mass set to 0.3. The scales is 0.4, 0.4, 0,4. I have made the drag 0.06 and the bounce is looking better but the ball hops once the speed is increased.
     
    Last edited: Apr 13, 2016
  4. caseyboundless

    caseyboundless

    Joined:
    Oct 17, 2011
    Posts:
    590
    I've almost gotten it where it needs to be. ForceMode.Impulse helped a ton. Thanks!