Animation changes transform when entering game mode - unity3d

In my Unity 3D project I've added an animated body as a child to the Player object. The player moves as is should, with the right animations displaying for each key. The problem however is that the transform of the child changes when I enter game mode, meaning the character is walking above the ground. In scene mode it's relative to it's parent, it's grounded, but when I switch to game mode the character suddenly changes it's y-axis transform. I also checked the inspector for this object, it's y-axis changes.
I tried disabling the movement script, to check if this could have anything to do with it, but nothing changes. The transform still changes. I'm new to this problem, and every thread I've found on the topic hasn't helped much. Does anyone know what might cause this?
The hierarchy. mixamorig:Hips is the one changing it's transform. The animations and animation skin I'm using is from Mixamo.

Related

Character moving up with animation even with "Bake into pose" checked for Root Transform Position (Y) and no apparent movement in animation

DESCRIPTION OF THE PROBLEM
I have a character with a throwing animation that has a Rigidbody with "Use gravity" checked. At the moment of the throw, in the middle of the animation, the character moves up a from the ground.
OBSERVATIONS ABOUT THE PROBLEM
This upward movement does not seem to be present in the animation itself when viewed in Unity's animation inspector, nor is it present in Mixamo, which is where I got it from.
The character never comes down if I DO NOT check the option below and keeps climbing up each time the animation is played.
If I DO check it, then the character STILL goes up but immediately comes down once the animation is finished.
If I check "Freeze position (Y)" as below:
The problem stops but other animations such as death animations stop working as the character floats after dying.
I don't think it's the collider because the character stays well up off the ground after the animation ends and keeps going up more and more each time, staying far away from the ground.
The problem persists with "Apply root motion" unchecked in the Animator.
WHAT I HAVE TRIED
Disabling all scripts, removing the animation event that was present and fiddling with all of the settings that I mentioned here, to no avail.
QUESTIONS
1) Why could this be happening? How could I find the source of this movement given that I don't see it in Unity's animation inspector/Mixamo?
2) Is there a better fix than creating a StateMachineBehaviour script with OnStateEnter and turning on the Y constraint there and turning it off in OnStateExit?
I had the same problem as you.
In my case, the problem came from the definition of the NavMesh from a Plane. For some unknown reason, Unity created the NavMesh plane with a little elevation. Finally, I changed the plane to a cube and the navmesh succeeded, so the agents move well on zero height, as expected.
After many hours reviewing the animations and the different options, the problem was in the generation of the NavMesh.
Hope this can help you.

Unity Model Drifts during Idle Animation

Hi my idle animation is not working as intended. When the character is idling, it slowly moves out of place. I checked that the movement is not caused by the script.
It seems to be related to physics because when I turned on kinematics and turned off the character's collider the idle animation did not cause the character to drift. I scoured the web for similar problems, and can only think that my problem has to do with movement caused by the animation itself.
When I imported the animation from Blender I checked 'Baked Animation'. In Unity I also set 'Root Node' to None for the imported animations. From what I read, setting root node makes the animation interact with its surroundings (and move) whereas baked means the animation is purely visual. However, none of this solves the problem of the drifting idle animation. I am running out of ideas and would really appreciate your help.
I could manually freeze the position via script, but this seems like a workaround. Interestingly, when I first enter game view and the idle animation plays there is no drifting. However, after exiting a walking animation and playing the idle animation again I see the drifting behavior.
Looks like you just need to uncheck 'Apply root motion' in animation import settings (in the inspector when you clicked on animtion file).
Root motion is the main reason why a 3d model moves away from its pivot without the help of a script. uncheck it from the import settings.

Problem animating the position of a GameObject in Unity while moving it

I am working on moving a Cube across the screen when I press an arrow and display two different animations depending on if it is moving or idle. I used a very basic translation to do this when I press the right arrow. I have two different animation states that work fine independently. One spins the cube when it is “idle” and the other makes to bounce up down in the “right” state. Both are 1 second animations. The idle animation spins the cube 360 degrees, and the right animation will move the cube up 1 unit then back down to its original position. Everything works well by itself. I included an image for the states for the animation.
Cube Animation States
In order to get the movement working with the animations I made an empty GameObject and made the cube a child if it. When the cube is idle it spins, and when I press right it moves and bounces up and down. The problem is when I release the right arrow the cube snaps back to its original position from the start of the last bounce animation. If I hold right for 10 seconds, and release it will only snap back to the beginning of the most recent iteration of the bouncing animation (not to when I started pressing right).
Does anyone know why this would happen? I tried changing some of the settings for the transitions, but it doesn’t seem like that is the problem.
Can you check that your idle animation modifying its position in any case.
First, you can't move the game object with animation.
you can have the rotate animation in the cube but not the translating part.
Because when the animations switch between the states the object will be moved to its original position.
solution:
-Create a script and attach the script to that game object.
-use translate functions to move the object

Unity Oculus - Rotating empty parent on character rotates on a weird axis when player isn't standing at origin

Sorry I know the title is really confusing.
Basically the camera and hands are nested under an empty object. This empty object is then used to rotate the character and teleport the character. Thing is, the camera is able to freely move around and away the empty object. Making rotation seem like you're running in a circle instead of just rotating. Then when you teleport it's a little offset. Like if you shoot the teleport beam straight down you move because it's teleporting the empty object to the camera which moves the camera.
So if the headset and camera aren't exactly on top of the empty object everything gets wonky. I understand the problem just can't figure out a solution.
I tried resetting the position on every teleport but you can still move away and spin in circles. As well as resetting resets the orientation and that's not exactly what I need.
Any help would be greatly appreciated.
There's a few ways to approach this. A crude, and not very elegant solution would be to parent your camera parent to yet another object, created in runtime, that would assume the position of the actual player camera when the rotation starts. You can reparent objects dynamically, so you could rotate this newly spawned object, which would give you the desired effect, and then loose the top parent when the rotation stops.
Alternatively you could move your camera parent as you rotate it, based on transforming the position relative to the player camera position. A bit more elegant but there's probably a few lines of math that you would have to write

Unity 5.3.8 Animator - Glitch?

I created a bunch of non-AI animations for enemies that do basic back.forth or up/down motions. Everything was working perfect until I started working on the Boss of the level. The boss has his own tag "Boss" and enemies have their own tag as well. Anyway, the problem is when I click start, every enemy leaves the game board. I can see them animated above the game board still doing their routines.
Any clue as to why this happened and how to fix it? I'd really, really hate to have to scrap all the enemies and start from scratch...
I used the Animation tool inside unity.
Extra Note: I created an EMPTY and moved all of my enemies into that Empty object to clean the hierarchy panel up. The animations were fine before this.
************** Currently Resolved **************
Whew! Okay, so apparently Unity doesn't like it when you move your animated stuff into an empty AFTER being animated. I FIXED them by simply removing them from the EMPTY that I had placed them in. However, I'd still like to know why this is. So any useful resources, links, manuals, personal insight/observations or anywhere I can read up on this would be appreciated!
Here is an explanation what happened:
The moment you dragged them all into the empty GameObject I guess this object probably wasn't placed on 0,0,0 in the Scene.
So Unity automatically changed all the local position values of your enemy items to fit the current position offset to the empty object.
Result: In the editmode they don't change their actual global position in the scene but their local position. This is supposed to happen if you just want to organize stuff.
However, now when you start the game and the animations are played, the animators change all the local positions to whatever is stored in your animations.
Result: all objects jump back to their original localPosition which had an offset to the empty GameObject.
To solve this make sure the empty GameObject is at position 0,0,0 and optimally has rotation 0,0,0 and scale 1,1,1 before you drag anything into it.
Easiest way to achieve that is by clicking reset in the empty objects Transform component before starting to drag stuff into it.