- Home /
Modifying script values using animations
Hi! After making my game's animations, I realized that enabling "Apply Root Motion" on my player's Animator will have some weird side effects on it's movement (Things like the animation trying to jump, and the Rigidbody pulling it down during the jump, so when the jump ends, the player would end being inside the floor, i.e).
I tried to move the animation's root using the rigidbody itself (forces). To do so, I've added two serialized floats to my player's script, whose work like triggers to apply forces externally (i.e, Setting them to x=2, y=0 would apply a force of (2,0) and then reset both values to 0).
I can't figure out a way to modify those values using keyframes. Sometimes, the Animation Editor will just reset them to 0 as soon as I try to change them (when directly setting the value). Sometimes it will just set all keyframes to the same value (when recording changes).
What am I doing wrong? Is there some checkbox I've to enable to allow Animations to modify values, or some configuration I've not seen? Please let me know if you need any extra information to find out the issue. Thanks you all ^^
PD: I've also tried setting both values to public, same results.
Edit:
@iJuan You are going down the self-destruct road. Dont apply rigidbody onto animation.
In humanoid animation clip. Click on the file clip. Scroll inspector down below. There is something call Loop offset and Root Transform position. Unlick Y root transform position. Then you will see an "Offset" value that show how high your character can jump during that clip play(down far below).
@TheWorstUsername I've managed to make animations and the rigidbody work together by baking Y root motion into the bones and applying root motion in the animator (As my animations don't move a lot trough Y axis). But can't do that on the X axis.
Punctually, my run and walk animation are both mocaps, so I need the animation to be able to control root's transform, but I also need the player to fall if there's no ground below him. If there was a way on disabling rigid body on the X axis (maybe I could try setting the friction of everything to 0?), I suppose it should work, but I'm not really sure if that would be a good solution.
Also, I need the rigidbody to add extra force to the jump animation (mocap jump isn't high enough for a platform game), and would like to manage sounds directly from animation (making triggers for different sound effects and calling them in certain key frames). In any case, the animation editor should let me modify a script's public variable using key frames
@ijuan Like I say you are going the self-destruct way.
I dont use root animation to control player movement anymore. I would use it to sample movement speed then apply it to script speed-controller. Because if you use root control - motion. You need perfect animations for that which are normally must be craft by hand for each project.
I guess what you want is a type of AA animation that play sound when feet reach ground and play a certain type of movement when this far x distance from ground.
That's I$$anonymous$$ and raycast territory. It's pretty advance stuff and weeks of work. You would have 2 raycast from under both feet(to check ground surface and type of terrain you are on). 2 another from both knees(to detect how far below that you have jump --- then choose a frame based on height and blend the remain animation with landing).
$$anonymous$$y best advices would be give up and turn off all root animation. Control all motion with scripts. Add force to rigid body like you said. Like when start jumping -> add force -> play jump animation. When rigidbody falling down (detect with update) -> Play falling animation. Raycast how far below -> Play landing animation based on time since the moment jump.
@TheWorstUsername I am actually using the raycasts you spoke of lol. Having root motion disabled for animations, isn't there any way to modify a script's variable using animation's keyframes? As I've tried in the gif above