#Character animation blending
1 messages · Page 1 of 1 (latest)
Your blend tree needs to be more complicated
Kidding of course, but there are a few things I would recommend
First, to solve your smoothing issue, you need to accelerate your character up to speed
The animation is directly tied to the speed of your character, if your character velocity snaps from (0, 0, 0) to (0, 0, 1) then your animation will also snap
then how i can snap velocity but dont snap animation ? made exit time ib blend tree
like that but in blend tree
Well, you will have to use a separate parameter that smoothly increases to your current speed
but i havent smooth movement
speedParameter = Mathf.MoveTowards(speedParameter, moveSpeed, Time.deltaTime)
I recommend you smooth the actual player movement instead though
im just set animation values based on input
Alright, well you need to smooth the values
there maxDelta parameter
Paste the code and I'll show you
public void Update()
{
if (!isLocalPlayer) return;
UpdateAnimatorProperties();
}
private void UpdateAnimatorProperties()
{
var movementInput = Inputs.Player.Movement.ReadValue<Vector2>();
if (IsRunning)
movementInput *= 2;
Animator.SetBool("IsInAir", IsJumping);
Animator.SetFloat("MovementX", movementInput.x, .1f, Time.deltaTime);
Animator.SetFloat("MovementZ", movementInput.y, .1f, Time.deltaTime);
}
its mirror NetworkBehaviour tho im using isLocalPlayer
public void FixedUpdate()
{
if (!isLocalPlayer) return;
ApplyGravity();
HandleMovement();
HandleRotation();
}
private void HandleMovement()
{
var movementInput = Inputs.Player.Movement.ReadValue<Vector2>();
var moveDirection = transform.forward * movementInput.y + transform.right * movementInput.x;// new Vector3(movementInput.x, 0, movementInput.y);
var deltaMove = moveDirection * (IsRunning ? RunSpeed : WalkSpeed);
if (CharacterController.isGrounded) IsJumping = false;
if (Inputs.Player.Jump.ReadValue<float>() > .5f && CharacterController.isGrounded)
{
deltaMove.y += CurrentJumpVelocity = JumpVelocity;
IsJumping = true;
Animator.SetTrigger("Jump");
}
if (IsJumping)
{
CurrentJumpVelocity -= Gravity * Time.deltaTime;
deltaMove.y += CurrentJumpVelocity;
}
CharacterController.Move(deltaMove * Time.deltaTime);
}
also movement
public float acceleration = 5f;
Vector2 playerVelocity = Vector2.zero;
private void UpdateAnimatorProperties()
{
var movementInput = Inputs.Player.Movement.ReadValue<Vector2>();
if (IsRunning)
movementInput *= 2;
playerVelocity = Vector2.MoveTowards(playerVelocity, movementInput, acceleration * Time.deltaTime);
Animator.SetBool("IsInAir", IsJumping);
Animator.SetFloat("MovementX", playerVelocity.x, .1f, Time.deltaTime);
Animator.SetFloat("MovementZ", playerVelocity.y, .1f, Time.deltaTime);
}```
Here I added playerVelocity and acceleration
Instead of feeding movementInput into your parameters directly, it instead changes playerVelocity per frame
playerVelocity is then what we feed into your parameters
playerVelocity = Vector2.MoveTowards(playerVelocity, movementInput, acceleration * Time.deltaTime);
why?
probably
playerVelocity = Vector2.MoveTowards(playerVelocity, movementInput * acceleration , Time.deltaTime);
?
No
The second parameter of MoveTowards represents the max speed
The third parameter represents how fast playerVelocity approaches max speed, the acceleration
ehhh
how i can made curve for that?
like start action more quicly and stop it more quicy
@random sail tho with simple float accelerations it looks a bit better
private void UpdateAnimatorProperties()
{
var targetAnimationVelocity = Inputs.Player.Movement.ReadValue<Vector2>();
if (IsRunning)
targetAnimationVelocity *= 2;
MovementAnimationVelocity =
Vector2.MoveTowards(MovementAnimationVelocity, targetAnimationVelocity, Time.deltaTime * MovementAnimationVelocityMultiplier);
Animator.SetBool("IsInAir", IsJumping);
Animator.SetFloat("MovementX", MovementAnimationVelocity.x, .1f, Time.deltaTime);
Animator.SetFloat("MovementZ", MovementAnimationVelocity.y, .1f, Time.deltaTime);
}
Move your character using MovementAnimationVelocity
Then your animation matches the speed
how?
Tell me how you're moving your character
also its probably bad idea (cuz it must be shooter)
private void HandleMovement()
{
var movementInput = Inputs.Player.Movement.ReadValue<Vector2>();
var moveDirection = transform.forward * movementInput.y + transform.right * movementInput.x;// new Vector3(movementInput.x, 0, movementInput.y);
var deltaMove = moveDirection * (IsRunning ? RunSpeed : WalkSpeed);
if (CharacterController.isGrounded) IsJumping = false;
if (Inputs.Player.Jump.ReadValue<float>() > .5f && CharacterController.isGrounded)
{
deltaMove.y += CurrentJumpVelocity = JumpVelocity;
IsJumping = true;
Animator.SetTrigger("Jump");
}
if (IsJumping)
{
CurrentJumpVelocity -= Gravity * Time.deltaTime;
deltaMove.y += CurrentJumpVelocity;
}
CharacterController.Move(deltaMove * Time.deltaTime);
}
public float acceleration = 5;
Vector3 playerVelocity;
private void HandleMovement()
{
var movementInput = Inputs.Player.Movement.ReadValue<Vector2>();
var moveDirection = transform.TransformDirection(new Vector3(movementInput.x, 0, movementInput.y));
var deltaMove = moveDirection * (IsRunning ? RunSpeed : WalkSpeed);
if (CharacterController.isGrounded) IsJumping = false;
if (Inputs.Player.Jump.ReadValue<float>() > .5f && CharacterController.isGrounded)
{
deltaMove.y += CurrentJumpVelocity = JumpVelocity;
IsJumping = true;
Animator.SetTrigger("Jump");
}
if (IsJumping)
{
CurrentJumpVelocity -= Gravity * Time.deltaTime;
deltaMove.y += CurrentJumpVelocity;
}
playerVelocity = Vector3.MoveTowards(playerVelocity, moveDirection, acceleration * Time.deltaTime);
CharacterController.Move(playerVelocity * Time.deltaTime);
}