I Changed the movement of my character to move with WASD, when setting the animator float i don’t know what to pass in, if I use “speed” the animator set him to run and he doesn’t stop, the “direction.magnitude” he stays idle. I really don’t want to use “set bool” lol, trying to keep the float because of the blend tree animations.
direction.magnitude is the variable to use… you may have to play around with the scale to fit your character… leave off the .1f and Time.deltaTime, instead, you’re looking for the approximate distance covered by the run animation in one cycle. This will vary from animation to animation so you’ll have to discover it through trial and error…
example:
float animationFactor = 2.0f; // it probably won't be this value, experiment until it looks right.
tpanimator.SetFloat("Forward", direction.magnitude*animationFactor);
I tried to use the same UpdateAnimator that the enemies use for the player but it doesn’t work, my guess is the the old Move is base on the navmeshagent’s destination and the player is not in a way. In short the enemies move fine from the same animation blend tree.
I just took a glance over your earlier code… and I’m wondering about the value of direction…
In Move(), direction is passed to the Move function, and calculations are made off of it… all the calls to direction in Move() are the local value inside Move(Vector3 direction)
Meanwhile in UpdateAnimator(), you’re basing your speed on direction.magnitude but where is this value coming from? It is clearly a global value… where is it set? Is it the same value as direction?
So i’ve been playing around with other ways to code movement to move the Player, in the Control script is the InputAxis for vertical and horizontal.
This is in the Update in the Control script and it calls to the Move
float h = Input.GetAxisRaw("Horizontal");
float v = Input.GetAxisRaw("Vertical");
if (cam != null)
{
// calculate camera relative direction to move:
camForward = Vector3.Scale(cam.forward, new Vector3(1, 0, 1)).normalized;
move = v * camForward + h * cam.right;
}
else
{
// world-relative directions in the case of no main camera
move = v * Vector3.forward + h * Vector3.right;
}
tpcharactermove.Move(move);
In the UpdateAmimator() I’ve tried passing in “tpanimator.SetFloat(“Forward”, speed);” the Player runs but doesn’t stop animating so it runs in place.
If I pass in “tpanimator.SetFloat(“Forward”, direction);” I get an error “cannot convert from UnityEngine.Vector to float”
So the Player animation moves but it didnt stop and looking at my old code I see something i did not do to this new one, which is put the UpdateAnimator in void Update lol XD, so adding the Vector direction to the UpdateAnimator worked and i just needed to put it in void Update. Player clips to a stop tho.
Sorry just noticed that when the Player speed is slowed, the animation doesn’t change because of the animationFactor, I’m brainstorming atm and was wondering if you had any ideas.
Thinking about what you said, I was going to make the animationFacter = the speed, then thought just put the speed in place of the animationFacter lol, so I took out the animationFacter. It works now so when the speed changes (slowed or sprinting) the animation scales with it.