- Home /
Best approach for handling catching/throwing/bouncing of a ball
I am porting over some concepts from XNA to Unity. I am looking at a sport game which the player can pick up the ball, catch the ball, bounce and kick the ball. Now within XNA I added a bone to my rig specifically for the ball. So when the bounding box (collider) came in contact with the ball the animation would kick in and the ball model would be attached to the bone in the animation. Same thing with the likes of bouncing it, ball is attached to a bone in the animation.
This all looks fine, but I don't know if it is the best practice, plus it was difficult to release the ball from the bone until the end of the animation. When kicking the ball it should be unattached from the bone when it hits the foot, at a certain frame in the animation, and force applied to it. But I couldn't work out how to find that specific frame of animation, but I assume that was more my lack of knowledge at the time (4/5 years ago) rather than the inability to do it.
So my question is, what would be the best way to approach this? Is my method, of creating new bone in rig and attaching ball the best way forward or is there better method?
Has anyone got any insight into this problem? I don't know if I phrased it right but there is bound to be someone who has done something similar.
Answer by Pysassin · Feb 05, 2013 at 10:21 AM
You could use the physics engine to do all of that. Give the ball arigidbody wih a custom physics material and set its bounciness to max so that it doesnt lose momentum after the bounce for dribbling. Then if you kick it just un parent lower the bounciness and add some foward relative force.
You can also just use the animation you have for bouncing or whatever works the easiest just turn is$$anonymous$$inematic off while animating then when you want to kick the ball turn is$$anonymous$$inematic on and add the force. Either way physics will be helpful for ya
I was thinking about using the physics engine, but how do you set it to stay in the hands for a period, bounce just right so it comes back into the hands, that sort of thing? Is there any examples out there?
I posted that last comment and didn't notice your comment before that. Ok, I'll give it a go and see what works best. Cheers.
If you use physics to bounce lock the rotations and x z positions and make the ball a child of the hand. That way physics makes it go up and down and it always goes to your hand because it moves with it
Yeah, I'll probably stick with the bone animation. If the player was standing still constantly then the physics animation of straight up and down might work. But when the player is running, the bounce will need to go a bit further ahead and bounce back into the hands to look realistic. This will be easier done with just the bone animation. Cheers though.
Answer by Loius · Feb 04, 2013 at 10:45 PM
That's the method I've used. It makes sense.
Unity animations don't have frames, they have time. Your specific frame occurs at:
if ( clip.time > (targetFrame/framesInAnimation) ) { // release ball // }
Cheers, I'll try to reimplement it this method for the time being, unless someone has a better idea?
Your answer
Follow this Question
Related Questions
Can the animation editor create local rotational data? 3 Answers
Adding animation clips via script 2 Answers
Can I make animations snap to a frame? 1 Answer
How to select an animation clip by index number? 7 Answers
How to edit fbx animations? 1 Answer