Question by
Starklndustries · Jan 29, 2020 at 05:46 AM ·
unity 2dslidingmovementsslowing-down
How to make character slow down when he is sliding until eventually he stops moving.
private void Update()
{
SetAnimationState();
}
private void FixedUpdate()
{
if (Input.GetKey("d") || Input.GetKey("right") && !isDead && !isHurting)
{
rb2d.velocity = new Vector2(runSpeed, rb2d.velocity.y);
if (isGrounded)
{
animator.SetBool("IsRunning", true);
}
Vector3 characterScale = transform.localScale;
characterScale.x = 2;
transform.localScale = characterScale;
}
else if (Input.GetKey("a") || Input.GetKey("left") && !isDead && !isHurting)
{
rb2d.velocity = new Vector2(-runSpeed, rb2d.velocity.y);
if (isGrounded)
{
animator.SetBool("IsRunning", true);
}
Vector3 characterScale = transform.localScale;
characterScale.x = -2;
transform.localScale = characterScale;
}
else
{
if (isGrounded)
{
animator.SetBool("IsRunning", false);
}
rb2d.velocity = new Vector2(0, rb2d.velocity.y);
}
}
void SetAnimationState()
{
if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow) && isGrounded)
{
animator.SetBool("IsSliding", true);
}
else
{
animator.SetBool("IsSliding", false);
}
}
Comment
Your answer
Follow this Question
Related Questions
Successive AddForce calls additive? 0 Answers
How to hide specific texts in a dialogue box 0 Answers
All instantiated objects having same location, 0 Answers
Cinemachine Targetgroup Zoom Speed 0 Answers