This is the first time I am trying to implement a basic animation to my object. My object which is a ball moves in the forward direction of its transform. I created a basic 360 degree rotation anim using Unity’s Animation tool and applied it to the ball so that when my ball moves around in the scene it looks like its rotating at the same time. The animation plays correctly but when I place it in the update method of ball script, it only keeps playing the animation but not do anything else like update its position every frame. I have switched off the Play Automatically checkbox but still it doesnt work. Here is my code below
for the update function.
Is it something to do with the rigid body attached? I can play the animation but not update the position at the same time but when I remove the animation the object updates per frame and moves around. What could be the problem?
The animation overrites the settings from the rigidbody. One solution may be to place the animation with the mesh in a child object of the rigidbody. Like that the animation doesn’t clear the position settings from the rigidbody and it locally plays the animation, relative to the rigidbody.
Awesome, perfect! I deleted my animation on parent rigidbody, added a child object and made animations to this child object. On my parent object i unchecked mesh renderer and applied all my parent materials to the child object. I hope this is what you meant. It works though
There is no need to even make it as a child. You can just Use the combination of…
this.GetComponent.enabled=true;
this.GetComponent.enabled=false;
and
this.GetComponent.Play();
Great explanation! Using the new 2D animation (preview) package (don’t use it, it’s terrible), and had the animation override the forces being added to the Rigidbody.
Created a child object, added the animator component to that object and moved all other child objects to that new object with the animator.
Ex:
MainGameObject (rigidbody, script, colliders, no animator!)
AnimationParentObject (only has the animator component)
Here’s the rule: any object that has a keyframe in the currently active animation cannot move (except for by the animator), it’s FROZEN. The rule stretches. If there is a transition arrow from the currently active animation to another, that one is considered active and no objects with keyframes in that animation are allowed to be moved outside the animator.
Summary: If an object cannot move because of the animator, it is involved in the currently active animation or one of the transition animations PERIOD
This is the bare minimum of information to report:
what you want
what you tried
what you expected to happen
what actually happened, log output, variable values, and especially any errors you see
links to documentation you used to cross-check your work (CRITICAL!!!)
The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?