I made a small playermovement for a 2d game and its fine till i jump at a wall and it just floats there till i stop moving,i tried making the movespeed 0 when colliding but the problem is that the wall itself has a platform above it(standing on a wall) and i want the player to move normally even when hitting a wall but the gravity affect him.so how can i fix it?
(i don’t the movements to be Axis Horizontal but arrows so don’t care about it)
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float movespeed = 5f;
public float jumpforce = 12.5f;
private Rigidbody2D rb;
private bool IsGrounded1;
public Transform groundCheck;
public float groundCheckRadius = 0.2f;
public LayerMask groundLayer;
void Start()
{
rb = gameObject.GetComponent<Rigidbody2D>();
}
void Update()
{
CheckGrounded();
move();
jump();
}
void CheckGrounded() {
IsGrounded1 =
Physics2D.OverlapCircle(groundCheck.position,
groundCheckRadius,
groundLayer);
}
void move(){
float moveInput = 0f;
if (Input.GetKey(KeyCode.RightArrow)) {
moveInput = 1f;
}
if (Input.GetKey(KeyCode.LeftArrow)) {
moveInput = -1f;
}
rb.velocity = new Vector2(moveInput * movespeed, rb.velocity.y);
}
void jump(){
if (IsGrounded1 && (Input.GetKeyDown(KeyCode.UpArrow))) {
rb.velocity = new Vector2(rb.velocity.x, jumpforce);
}
}
private void OnDrawGizmos() {
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(groundCheck.position,groundCheckRadius);
}
}