Is it possible to apply root motion to non humanoid objects? - unity3d

Is it possible to apply root motion to non humanoid objects?
I need the object position to be incremental after every animation in animation controller. Position in default is reset to starting point of current clip. How do i prevent this? I need to make animation state machine with part of clips to make incremental changes in objects properties.

From Unity Documentation :
Generic Root Motion and Loop Pose
This works in essentially the same
as Humanoid Root Motion, but instead of using the Body Transform to
compute/project a Root Transform, the transform set in Root Node is
used. The Pose (all the bones which transform below the Root Motion
bone) is made relative to the Root Transform.
Apparently yes you can use the RootMotion on non-humanoid objects. You need to set the correct Root node in the Rig section for models and animations, this should be the node that actually contains the root motion that you want applied to your generic model.
Here's a thread about it on Unity Forums.

Related

Get Orientation of SCNNode Swift [duplicate]

I am working on a basic racing game using Apple's SceneKit and am running into issues simulating a car. Using the SCNPhysicsVehicle behavior, I am able to properly set up the car and drive it using the documented methods.
However, I am unable to get the car's position. It seems logical that the SCNPhysicsVehicle would move the SCNNodes that contain the chassis and the wheels as the car moves but the SCNNodes remain at their original position and orientation. Strangely enough, the chassis' SCNPhysicsBody's velocity remains accurate throughout the simulation so I can assume that the car's position is based off of the SCNPhysicsBody and not the SCNNode. Unfortunately, there is no documented method that I have found to get an SCNPhysicsBody's position.
Getting a car's position should be trivial and is essential to create a racing game but I can't seem to find any way of getting it. Any thoughts or suggestions would be appreciated.
Scene Kit automatically updates the position of the node that owns an SCNPhysicsBody based on the physics simulation, so SCNNode.position is the right property to look for.
The catch is that there are actually two versions of that node in play. The one you typically access is called the "model" node. It reflects the target values for properties you set, even if you set those properties through an animation. The presentationNode reflects the state of the node currently being rendered — if an animation is in progress, the node's properties have intermediate values, not the target values of the animation.
Actions, physics, constraints, and any scene graph changes you make inside update/render loop methods directly target the "presentation" version of your scene graph. So, to read node properties that have been set by the physics simulation, get the presentationNode for the node you're interested in (the node that owns the vehicle's chassisBody physics body), then read the presentation node's position (or other properties).
I have the same problem with my player node.
I move it with applyForce (to manage collision detection).
But when i check node position after some movement, the node position has not move (presentation node is the actual position as rickster write in his answer)
I manage to update the scnNode.position with renderer loop
You have to set position of your node with the presentationNode position.
node.position = node.presentationNode.position
Set this into renderer(_: updateAtTime) and your node position will sync with any animation you made to the physicsBody

In unity, use maya exported animation and other anim make animator transition will reset object position

here is my unity project
here is my maya project
here is my old question
in my old question, I use paid unity asset animation occurs same problem, so I make similar animation with maya and reproduce it with free asset
see my gif
the bug is when ClimbReachTop finish and play Standing, the object position will be auto reset
when i use similar ClimbReachTop in this asset, the object position will not be reset
so how to make animator transition not reset object position
I'm sure it's not because "apply root motion" since I drag fbx model to unity editor > animation preview, it has not option to select "apply root motion"
update
as my old answer say, convert root motion animation into control rig, adjust anim, and re-convert to skeleton anim, the root object translate will be messy
but in many cases, I must convert anim to control rig to adjust it, so when get re-convert root-object-mesey result, I can edit root object in graph editor as my old answer say
and here is a tip to adjust re-convert anim to make it like ik anim:
in my case,i wanna change exist anim to root motion anim, convert to control rig to adjust maybe messy anim, so use following way
use tmp sphere express ik point(IkReferPoint). key by key, to make sure ik body part translate fixed in specific key range
for ex, in walk anim, in specific keys range, I hope leftFoot translate fixed
create ikreferpoint
in timeline, click key range start key, move ikreferpoint to leftfoot pos
to next key, move leftfoot to ikreferpoint pos
old answer
update
I make video, it convert not root motion animation to root motion animation for unity
attention: if in unity editor side, it still not root motion anim, unity editor > fbx inspector > animations > motions > root motion node > manually specific root motion node(in my anime, it's "root")
if imported to maya model has not root object, maya > create joint as root object and in outliner move model to root object, here is good tutorial
old answer
update
old answer make new anim work well, but if assign root object as HipsTranslation in hik, bake into control rig, and then bake into skeleton to make root motion, the root object translate will be unexpectely
so to convert exist animation to root motion anim, here is good tutorial, to exist anim, I can directly adjust root object translate in graph editor
old answer
update
old answer only give a way to make root motion with new skeleton, I find a common way to make root motion with new skeleton or exist skeleton
make root object
assign it to HipsTranslation
when do it, this root object's translate relative with hips will be fixed
it my old answer to adjust root object
in unity, manually fbx anim root object as motion > root node
old answer: following is just a way to make new skeleton
I find the solution, i should make root motion anim in maya
here is video tutorial
in short, in maya I should make root motion animation with root object, and in unity editor exported fbx animation inspector > animation > motion > root motion node > manually select my created root object
in unity animator transition, when one animation play finish and play next anim, character transform will be determine by this fbx anim root object
what is root object? in in my screenshot, it's vertical line from ass to bottom)
how to create root object?
maya > hik > skeleton > hips transition, it will generate hip parent object, set this parent object as root object, set root object translate to (0,0,0) and adjust hip to make sure whole model world position is same like old
above video also provide way to adjust this root object

Importing an exported .FBX from Blender to Unity object transform issue

Alrighty,
I have a dumpster model I have exported from Blender as an FBX. The transform, rotation and scales have all been applied in Blender. when importing into Unity and then adding to the scene, the model is elevated and rotated at an odd angle to the transform as per the image.
The model has an armature for animating the lids an I have applied the location, rotation and scale on it as well.
Any one else come across this or know of a fix?Thanks
Blender image
Incorrect dumpster transform and location image
The problem is that Blender uses the right-handed coordinate system which means the Z-axis is pointing upwards.
Unity uses the left-handed coordinate system which means the Y-axis is pointing upwards.
To fix this, set the X-axis rotation of the model to be -90. Press Ctrl+A and apply rotation. The X-axis rotation will look like it is now 0 after that. Set it to 90 again and export it to Unity.
This 3 minutes video should also help you do this if you are still confused.
If you still have problems, check your animation. Don't apply it to your model and see if it's the problem.
Also as a side note, you can use blender files (.blend) directly with unity. So every time you modify them inside your project folder they change in unity as well.
The simplest way to solve this would be as follows:
Create a dummy game object (D)
Transform/offset the position of D to make sure your object's position align with the dummy parent
Put your game object as the child of the dummy game object D
You can then apply transform on D, rather than your own game object directly.

Does having Root Motion applied prevent moving a transform position relative to world coordinates?

I have "GameObject 0" (GO0) with an animation controller that used parameters to transform states and is used as a wrapper for "GameObject 1"(GO1). "GameObject 1" has an animation controller that has Root Motion applied. Within GO1 there are 3 game objects whos animation is in the same animation clip as GO1.
This allows me to place GO1 in world coordinates and animate GO1's children in local coordinates to maintain relative positioning.
However, I am wish to move one of the children of GO1 to a world coordinate that is not relative to GO1. I have used script and Vector3.Lerp / Vector3.MoveTowards functions, but they are not working as expected. Is the Root Motion interfering with the Lerps?
I have change the script to add a new parent to the child object and animating the new parent. This seems to work but the rotation of the new parent is causing a new issue.

What's root motion and how it works?

I'm reading Unity Animation cookbook book. And I'm stuck at "Root Motion" topic. All I can understand now is Root motion allows the GameObject to move with the motion clip without coding. and it depends on the root node. But I can't imagine/understand how ? or what're that related properties like "Bake to pose" .. what's the pose..? I searched the web to find anyone talking about it.. but no helpful tutorials there! I tried to read from unity docs about the topic but it made it worse..
https://docs.unity3d.com/Manual/RootMotion.html
Please help me with example/link/replay
After spending more time searching/watching videos/ reading from other books to understand everything. I'll put my answer here for anyone face same difficulties understanding this topic
Treadmill vs root motion: There are two types of animation, treadmill and root motion. Treadmill means that the animation stays at the origin and we use code to move that asset around. Root motion means the motion is built right into the animation and it's the animation that determines how far something moves rather than code.
Then you have to watch this video to get an idea about how it looks in Blender and later in Unity when you import the character & animation
https://www.youtube.com/watch?v=d5z9dEnE4DE
Root Transform Rotation: This option captures the rotation of the root node and
applies it to the whole game object. You can set it to Bake Into Pose to disable the
root motion rotation. With this option selected, the rotation will be treated as a
visual effect of the animation and will not be applied to the game object. You
should set it to true for every animation that shouldn't rotate the character. You
can set the Based Upon option to one of the following options:
Root Transform Position Y: This option captures the vertical movement of the
root node and applies it to the whole game object. You can set it to Bake Into
Pose to disable the root motion in the Y axis. With this option selected, the Y axis
motion will be treated as a visual effect of the animation and will not be applied
to the game object. You should set it to true for every “on ground” animation
(unless it's a jump).
Root Transform Position XZ : This option captures the horizontal (XZ)
movement of the root node and applies it to the whole game object. You can set it
to Bake Into Pose to disable the root motion in the X and Z axis. With this option
selected, horizontal motion will be treated as a visual effect of the animation and
will not be applied to the game object. You should set it to true for all stationary
animations (such as Idle).
Good animations may combine both traditional(treadmill) and root motion ways.
The Body Transform (Pose) is the mass center of the character.
The Root Transform is a projection on the Y plane of the Body Transform (Pose) and is computed at runtime.
If you want to transfer the body transform to the gameobject first you have to transfer it to the root transform because that is the one that is applied to the gameobject transform. to transfer, for example, the XZ motion of the body transform to the root transform, you need to uncheck bake into pose option.
All right except "You should set it to true for every “on ground” animation (unless it's a jump)."
More correctly will be: "You should set it to True for every animation, where you will move Character GameObject by Axis Y by code (Unity Script), also are including the Jumping animation. If you will not move the GameObject of the Character along the Y-axis (by code), but want to implement "Jump" as the movement of bones (parts of the character's skeleton) from the jump animation, if it is present in the animation that was imported, you must set it to False. Many popular the Jumping "In-place" animations doesn't include the movement of bones, which will track the full bones movement at real Character Jump (say simple - in these animations the Root Node not up on demanding height)."