Question by
robotrage · Aug 11, 2017 at 06:49 AM ·
2d gamecharacter movement
stop player from moving after button released.
//i want the character to instantly stop after button release
void FixedUpdate()
{
float horizontal = Input.GetAxisRaw("Horizontal");
rigidBody2D.AddForce((Vector2.right * speed) * horizontal);
if (rigidBody2D.velocity.x > maxSpeed)
{
rigidBody2D.velocity = new Vector2(maxSpeed, rigidBody2D.velocity.y);
}
if (rigidBody2D.velocity.x < - maxSpeed)
{
rigidBody2D.velocity = new Vector2(-maxSpeed, rigidBody2D.velocity.y);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
2D Character shakes when moving diagonally 0 Answers
How to flip my character with this script 0 Answers
how to jump in a 2D game 2 Answers
My player won't move, does anyone know why? 0 Answers
Player is bouncing when colliding with wall object 0 Answers