using UnityEngine;
public class Playermove : MonoBehaviour
{
public CharacterController controller;
public float Speed = 12f;
public float gravity = -9.8f;
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundMask;
Vector3 velocity;
bool isGrounded;
void Update()
{
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
if (isGrounded && velocity.y < 0)
{
velocity.y = -2f;
}
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * Speed * Time.deltaTime);
velocity.y += gravity = Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
}
}
-
Вопрос задан
-
106 просмотров