- Home /
Trouble during jump. Player sticking to the wall
I'm trying to put a skip script. The script that I found on the Craft Games website is the best I've tested so far, but I'm having a problem with it. I don't know if it's the script or something in the inspector, but during the jump and also in the fall, when the player touches the wall, instead of the it sliding normally, it gets stuck, and only falls again when I move away from the wall (An attached image shows the problem).
That is the script I am using (I am not the author of the script. I got the script here https://craftgames.co/unity-2d-platformer-movement/ ):
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Best_Jump : MonoBehaviour
{
Rigidbody2D rb;
public float speed;
public float jumpForce;
bool isGrounded = false;
public Transform isGroundedChecker;
public float checkGroundRadius;
public LayerMask groundLayer;
public float fallMultiplier = 2.5f;
public float lowJumpMultiplier = 2f;
public float rememberGroundedFor;
float lastTimeGrounded;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
Move();
Jump();
CheckIfGrounded();
BetterJump();
}
void Move()
{
float x = Input.GetAxisRaw("Horizontal");
float moveBy = x * speed;
rb.velocity = new Vector2(moveBy, rb.velocity.y);
}
void Jump()
{
if (Input.GetKeyDown(KeyCode.Space) && (isGrounded || Time.time - lastTimeGrounded <= rememberGroundedFor))
{
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
}
}
void CheckIfGrounded()
{
Collider2D colliders = Physics2D.OverlapCircle(isGroundedChecker.position, checkGroundRadius, groundLayer);
if (colliders != null)
{
isGrounded = true;
}
else
{
if (isGrounded)
{
lastTimeGrounded = Time.time;
}
isGrounded = false;
}
}
void BetterJump()
{
if (rb.velocity.y < 0)
{
rb.velocity += Vector2.up * Physics2D.gravity * (fallMultiplier - 1) * Time.deltaTime;
}
else if (rb.velocity.y > 0 && !Input.GetKey(KeyCode.Space))
{
rb.velocity += Vector2.up * Physics2D.gravity * (lowJumpMultiplier - 1) * Time.deltaTime;
}
}
}
Your answer
Follow this Question
Related Questions
My movement function with jump won't work with collider function 1 Answer
AddForce Movement Constraint 0 Answers
Why does this script make my camera jump when I move back? 1 Answer
Can't jump in C# 1 Answer
2D Character Jumps only 1 time 2 Answers