- Home /
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
Answer by Xedfire 1 · May 02, 2011 at 07:34 PM
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.
Is there any way I could send you the code and you could possible advise us where it is to be placed? I know this sounds so cheeky, but we are desperate right now :)
Answer by Chris D · May 02, 2011 at 08:24 PM
//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.
Like I said, we are very short of time so i apologise for my unfocussed questions.
it's just a matter of explaining a little clearer what you want. How are you handling the club? is there an animation that needs to play out? did you want the ball to actually be impacted according to the unity physics engine or did you want to have fine-tuned control from some sort of user interface. Any details you can add to the question will help people give you better responses.
Your answer
Follow this Question
Related Questions
Addforce after Instantiate 2 Answers
Add Force Problem 0 Answers
Force Help 0 Answers