So I’ve made a simple third person parkour script, and want to implement wall jumping, and I’m not sure how to go about doing it.
Here’s how I detect wall collision:
void OnCollisionEnter(Collision collision)
foreach (ContactPoint contact in collision.contacts)
{
if (!onGround && rb.position.y > -16f)
{
Debug.DrawRay(contact.point, contact.normal, Color.red, 10f);
}
}
}
And heres my movement script:
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && onGround == true)
{
speed = jumpSpeed;
onGround = false;
rb.AddForce(jump * jumpForce, ForceMode.Impulse);
}
}
void FixedUpdate()
{
moving = Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D);
if (moving)
{
transform.rotation = Quaternion.Euler(0, Camera.rotation.eulerAngles.y, 0);
}
float x = Input.GetAxisRaw("Horizontal");
float y = Input.GetAxisRaw("Vertical");
Vector3 move = (transform.right * x + transform.forward * y);
move.Normalize();
rb.velocity = new Vector3(move.x * speed * Time.deltaTime, rb.velocity.y, move.z * speed * Time.deltaTime);
onGround = Physics.CheckSphere(new Vector3(transform.position.x, transform.position.y - 1, transform.position.z), spSize, Ground);
}
Any answers would be greatly appreciated, sorry if this is a stupid question I’m pretty new to Unity.