I’m not sure if this is the correct forum for this but it seemed like the most appropriate.
I’m using a blend tree and root motion to have characters on screen sprint to a location. The blendtree is controlled by a speed parameter to move between idle(0.0f) to full sprint(2.0f) (idle, walk, jog, run, full sprint).
If I set the value to run, I arrive too late, if I set the value to full sprint, I arrive too soon. So I’m trying to find a way to convert “I need to arrive at that spot in 1.53 seconds” to a value I can assign to speed so my blend tree locomotion will put the character at that spot in 1.53 seconds.
I’ve tried using MatchTarget, but that doesn’t seem to do much, I’m probably not using it correctly, but I’m not getting the results I expected.
Does anyone have any suggestions on how to adjust rootmotion locomotion so that characters don’t overshoot their target and get their too soon?
Also, it’s distinctly possible that the character might not be able to move fast enough to get there in time, and that’s fine, but he shouldn’t over shoot if he gets there too soon.
Yeah, I had the same problem with you, and it’s actually quite hard to fix.
You could try to make a stop animation, and blend it in such a way that when you trigger “Stop”, it will stop in that exact point (that means that the transition to stop animation should have Transition Duration as close a possible to 0). Now this will affect how your animations look.
Another thing that you can do (which seems to me a bit hacky), for each animation that transition in stop, try and calculate how much distance it takes (based on transition duration) in order for the character to fully stop. Then you can call the “Stop” trigger by subtracting that distance from the current destination.
Unfortunately, I’m yet to find an exact solution to this problem. I used the second method, and I achieved an OK result…
it’s better and cause less issues to control movement from script and keep animator for charactar movement look/feel.
if you want the whole process of accelerating / de-accelerating process… you really need to invest in many movement calculation and use scripts.
a simple solution for movement is like :
float perc = totaltime / totalduration;
vector3 position = vector3.lerp(startPos,endPos,perc);
float animatorSpeed = float.lerp(0f,4f,perc); //at perc = 0.5f the speed will 2f … now we need to slow down etc.
if(perc>0.5f)
animatorSpeed = float.lerp(4f,0f,perc); //speed will be zero when distance reached.