- Home /
fps script not working
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 . . .
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;
}
//Fire 1 if (Input.GetButtonDown("Fire 1")) {print("Pew!!!");}
//Fire 2 if (Input.GetButtonDown("Fire 2")) {print("puew!!!");}
}
}
Is "sprint!!" and "crouch!!" displayed in the console at all? If not, you might need to assign the corresponding keys to the names "sprint" and "crouch" in the Input $$anonymous$$anager.
Answer by arisharr · Nov 29, 2020 at 04:04 AM
you should test every line of your code which is about to running or whatever. do you have discord? I can help you in there. my username is Arisharr#2213
Your answer
Follow this Question
Related Questions
Player inversed inputs 0 Answers
Distribute terrain in zones 3 Answers
How can I make a character controller that changes positions on one click. 1 Answer
Character Controller Rotation 4 Answers
Animate child of FPSController 0 Answers