- Home /
Question by
kris1604stw · Jan 02 at 03:51 PM ·
climbing
How do i add wall climbing to my game?
Hey, i am new to Unity and would like the player to climb walls. I just don't know how. I have already made some simple movement using the Character Controller.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public CharacterController controller;
private Vector3 move;
private float horizontalInput;
private float verticalInput;
public float speed = 12f;
public float gravity = -9.81f;
private Vector3 velocity;
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundMask;
bool isGrounded;
void Update()
{
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
if(isGrounded && velocity.y < 0)
{
velocity.y = -2f;
}
horizontalInput = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
verticalInput = Input.GetAxis("Vertical") * speed * Time.deltaTime;
move = new Vector3(horizontalInput, 0, verticalInput);
controller.Move(move);
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
}
}
Comment
Your answer
Follow this Question
Related Questions
Issues with Mecanim and climbing 1 Answer
Climbing using OnTriggerEnter and Arrow Keys? 1 Answer
Help with implementing a wall climbing mechanic like botw? 0 Answers
Climbing script 0 Answers
Immersive climbing system. 0 Answers