- Home /
Question by
Amdragg · May 13, 2020 at 02:25 PM ·
jumpwall collisionwalljump
Creating a Wall Jump (Absolutely new to C#)
So in following a bunch of tutorials on Youtube, I've finally been able to set up a character that I've mapped controls to, even a jump feature. But, now I'm trying to implement a sort of wall jump, but in my research, I've haven't the slightest clue what to add to my already established code to do so:
using UnityEngine;
using System.Collections;
public class PlayerMove : MonoBehaviour
{
public CharacterController controller;
public float Speed = 7f;
public float gravity = -20f;
public float jumpHeight = 3f;
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundLayers;
Vector3 velocity;
bool IsGrounded;
void Update()
{
IsGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundLayers);
if (IsGrounded && velocity.y < 0)
{
velocity.y = -2f;
}
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 movement = transform.right * x + transform.forward * z;
controller.Move(movement * Speed * Time.deltaTime);
if (Input.GetButtonDown("Jump") && IsGrounded)
{
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
}
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
}
}
Comment
Your answer
Follow this Question
Related Questions
Third Person Player stuck on wall 0 Answers
Unity2D Platformer - Wall jumping with unity's physics 1 Answer
3d wall jumping with charter controller 1 Answer
Wall Jump Instead of Sliding up 1 Answer