I’m trying to Bild a simple caricature controller with sprinting, walking, crouching, and jumping,
but the sprinting and crouching don’t work, Please tell me wot I’m doing Ronge
I did change the inputs under project settings, input manager, so the fact that all my keywords are different is not the problem, also all of the buttons work I tested (that’s wot the print(“words”) are for)
I know that there is some sort of debug but I’m a bit new at unity C# and also I think changing the inputs messed that up.
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
//Public Float: Speed
public float WalkSpeed = 10f;
public float RunSpeed = 16f;
public float JumpSpeed = 8f;
public float CrouchSpeed = 8f;
//Public Float: Other
public float JumpHeight = 3f;
public float Gravity = -9.81f;
public float GroundDistance = 0.4f;
public float VScaleUp = 2f;
public float VScaleDown = 1f;
//Objects
public Transform GroundCheck;
public LayerMask GroundMask;
public CharacterController Controller;
Vector3 Velocity;
bool IsGrounded;
// Update Is Called Once Per Frame
void Update()
{
//Speed
float Speed = WalkSpeed;
//VScale
float VScale = VScaleUp;
Controller.height = VScale;
//Input
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
//Movement Based on Wear The Players Facing
Vector3 move = transform.right * x + transform.forward * z;
Controller.Move(move * Speed * Time.deltaTime);
Controller.Move(Velocity * Time.deltaTime);
//GroundCheck
IsGrounded = Physics.CheckSphere(GroundCheck.position,
GroundDistance, GroundMask);
Velocity.y += Gravity * Time.deltaTime;
//IsGrounded
if (IsGrounded && Velocity.y < 0)
{
Velocity.y =-2f;
}
//Sprint Function
if (Input.GetButtonDown("Sprint") && IsGrounded)
{
print("Sprint!!!");
Speed = RunSpeed;
}
//Jump Function
if (Input.GetButtonDown("Jump") && IsGrounded)
{
Velocity.y = Mathf.Sqrt(JumpHeight * -2f * Gravity);
print("jump!!!");
}
//Crouch Function
if (Input.GetButtonDown("Crouch") && IsGrounded)
{
print("Crouch!!!");
VScale = VScaleDown;
}
}
}