-
Notifications
You must be signed in to change notification settings - Fork 58
Open
Description
// PlayerMovement.cs
using UnityEngine;
[RequireComponent(typeof(CharacterController))]
public class PlayerMovement : MonoBehaviour
{
public float speed = 5f;
public float gravity = -9.81f;
public float jumpHeight = 1.2f;
public Transform cam;
CharacterController controller;
Vector3 velocity;
void Start()
{
controller = GetComponent<CharacterController>();
}
void Update()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
Vector3 move = cam.right * h + cam.forward * v;
move.y = 0;
controller.Move(move * speed * Time.deltaTime);
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
}
}
Metadata
Metadata
Assignees
Labels
No labels