Question by
ArcherB6 · Jan 06, 2021 at 08:30 AM ·
2d-platformerplatformercharacter movement
Character wont stop Bouncing
I am making my first ever game in Unity a 2D platformer, I am just getting the basic down first and I have run into a problem, My character wont stop bouncing on the floor. PLEASE HELP
UPDATE, I removed the floor objects and replaced them now i dont bounce, i just cant jump.
Here is my code, I followed the Muddy wolf Games tutorial:
public class PlayerMovement : MonoBehaviour { public float movementSpeed; public Rigidbody2D rb;
public Animator anim;
public float jumpForce = 20f;
public Transform feet;
public LayerMask groundLayers;
float mx;
private void Update()
{
mx = Input.GetAxisRaw("Horizontal");
if (!Input.GetButtonDown("Jump") && IsGrounded())
{
Jump();
}
if (Mathf.Abs(mx) > 0.05f)
{
anim.SetBool("IsRunning", true);
} else
{
anim.SetBool("IsRunning", false);
}
anim.SetBool("IsGrounded", IsGrounded());
}
private void FixedUpdate()
{
Vector2 movement = new Vector2(mx * movementSpeed, rb.velocity.y);
rb.velocity = movement;
}
void Jump()
{
Vector2 movement = new Vector2(rb.velocity.x, jumpForce);
rb.velocity = movement;
}
public bool IsGrounded ()
{
Collider2D groundCheck = Physics2D.OverlapCircle(feet.position, 0.5f, groundLayers);
if (groundCheck == null)
{
return false;
}
return true;
}
}
Comment
Answer by Superman19283 · Mar 22, 2021 at 03:40 PM
Try changing the gravity on the player to 5. That worked for me.