Adding Loft to a ball in a 3d golf game within Unity

Hi guys,

As a team of 5, we're creating a golf game as part of our second year University project. Following tutorials and editing them where needs be, we currently have our ball rolling and hitting objects, using collision physics. Unfortunately, we need to add loft to ball upon a hit from a club.

Would anyone be able to help us or guide us in the right direction as to how we can do this? Unfortunately, we are on a break from university and are currently unable to talk to our tutors.

We appreciate your help

Thanks

If your golf ball has a rigidbody, you can use rigidbody.AddForce(...). Go HERE for more info. Hope this helps, and good luck!

....

EDIT:

I just thought that I would edit my answer to provide extra information. So, the way that I would do what you're asking for would probably be...

  • Make a new script.

  • In that script, Use an OnCollisionEnter function to know when the ball is hit. Look at THIS tutorial for more info. Remember to check if you are actually colliding with the golf club.

  • In that OnCollisionEnter function, use rigidbody.AddForce(). See THIS.

  • Next, save your script and attatch it to your BALL.

//pseudocode

if(hit){
     rigidbody.AddForce(directionYouWantItToGoAsAVector3
                        *magnitudeOfForceToApplyAsAScalar)
}

put it in your update function, attached to your ball. You'll still need to write the program. Check out the documents and come back to ask focused questions if you have problems.