- Home /
How to add physics to an animation?
Hi I have an animation thats transform position is animated to move from Vector3(-1,0,0) to Vector3(1,0,0).
I'm trying to figure how to get physics to work with this animation, for example, if while the object is moving from Vector3(-1,0,0) to Vector3(1,0,0) hits another object, I want the hit object to react as if it had been hit with force.
I've tried using 'Animate Physics' on the animator and using a Rigidbody on the object that's being animated, and I've had no luck.
I believe you and I have run across the same issue:
http://answers.unity3d.com/questions/1188956/animator-animate-physics-does-nothing.html
In found out why the physics weren't working, check the accepted answer, maybe it'll solve your problem.
Answer by whisker-ship · May 19, 2016 at 08:52 AM
I found out why the physics weren't working for me, the object that was being hit had a script that set the rigidbody's velocity to:
new Vector3(Input.GetAxis("Horizontal", 0, Input.GetAxis("Vertical")).
So the velocity would always be that even if hit by an object, resulting in its receiving collision physics not working. @Julien.Lynge
Answer by Amanna · May 19, 2016 at 06:14 AM
You can disable the animator component when collides with objects, and then the rigidbody will work for you to apply physics to it .
to disable Animator :
Animator anim = gameObject.GetComponent("Animator");
anim.enabled=false;
Sorry Amanna, but the poster clearly asked about how to "get physics to work with this animation". Your answer - to turn of animations - doesn't actually address the issue.
Answer by HarshadK · May 19, 2016 at 06:05 AM
There are few things you need to check for:
The object being hit also has Rigidbody and is not static.
Uncheck 'Apply Root Motion' from the Animator component on the object that's being animated.
Update Mode is 'Animate Physics'.
I can't speak for @whisker.ship, but those were among the first things I tried, and they make no difference.
Have you actually tried setting this up in a scene?
Yeah, that would be awesome! Since It sounds like @whisker.ship has solved his issue, do you $$anonymous$$d posting it here: http://answers.unity3d.com/questions/1188956/animator-animate-physics-does-nothing.html ?
Your answer
Follow this Question
Related Questions
Manually Apply Cars Collision Response Force 0 Answers
rigidbody jumping and moving with constant speed without acceleration (with video ) 2 Answers
Limit How Far an Object is Pushed After a Collision 0 Answers
How to get Satisfying Collision Physics 1 Answer
Character Controller meets Rigidbody 1 Answer