Answer the question
In order to leave comments, you need to log in
How to remove wall jump?
I'm new to Unity and decided to start with a simple 2D platformer. After implementing the jump system, I ran into one problem, if the character crashes into the wall of the platform (its side part) and at the same time presses the jump button, then he will fly into space. Here is my code:
using UnityEngine;
public class Movment : MonoBehaviour {
public float speed, JumpPower;
public bool OnGround = true;
void Update() {
if (Input.GetKey(KeyCode.RightArrow))
transform.Translate(new Vector2(speed * Time.deltaTime, 0));
if (Input.GetKey(KeyCode.LeftArrow))
transform.Translate(new Vector2(-speed * Time.deltaTime, 0));
if (Input.GetKey(KeyCode.UpArrow) && OnGround) {
OnGround = false;
GetComponent<Rigidbody2D>().AddForce(Vector2.up * JumpPower);
}
}
private void OnCollisionEnter2D(Collision2D collision) {
if ((collision.gameObject.tag == "Platform")) {
Debug.Log("WellDone");
OnGround = true;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question