public class PlayerMov : MonoBehaviour
{
public CharacterController controller;
public float Speed = 12f;
public float gravity = -20;
public float JumpH = 3f;
public Transform groundCheck;
public float groundDis = 0.4f;
public LayerMask GroundMask;
Vector3 Velocity;
bool isGrounded;
void Update()
{
isGrounded = Physics.CheckSphere(groundCheck.position, groundDis, GroundMask);
if (isGrounded && Velocity.y < 0 )
{
Velocity.y = -2;
}
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * Speed * Time.deltaTime);
if (Input.GetButtonDown("Jump") && isGrounded)
{
Velocity.y = Mathf.Sqrt(JumpH * -2f * gravity);
}
Velocity.y += gravity * Time.deltaTime;
controller.Move(Velocity * Time.deltaTime);
}
}
If I change the +=
in Velocity.y += gravity * Time.deltaTime
to a -=
, I am staying on the ground but I am not able to jump. If I leave it, I am starting to float. I would be grateful if someone could help me solve this problem (I am trying to make a simple FP Controller using the CharacterController
component).
question from:
https://stackoverflow.com/questions/65872651/jumping-doesnt-work-after-adding-groundcheck 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…