using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FPSMovement : MonoBehaviour
{
public float _speed = 6.0f;
public float gravity = -9.81f;
private CharacterController _characterController;
private void Start()
{
_characterController = GetComponent();
if (_characterController == null)
Debug.Log("CharacterController is NULL");
}
private void Update()
{
float deltax = Input.GetAxis("Horizontal") * _speed;
float deltaz = Input.GetAxis("Vertical") * _speed;
Vector3 movement = new Vector3(deltax, 0, deltaz);
movement = Vector3.ClampMagnitude(movement, _speed);
movement.y = gravity;
movement *= Time.deltaTime;
movement = transform.TransformDirection(movement);
_characterController.Move(movement);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FPSMovement : MonoBehaviour
{
public float _speed = 6.0f;
private CharacterController _characterController;
private void Start()
{
_characterController = GetComponent<CharacterController>();
if (_characterController == null)
Debug.Log("CharacterController is NULL”);
}
private void Update()
{
float deltax = Input GetAxis("Horizontal”) * _speed;
float deltaz = Input.Getaxis("Vertical”) * _speed;
Vector3 movement = new Vector3(deltax, 0, deltaZ)
movement = Vector3 .Clamphagnitude (movement,
‘novenent.y = gravity;
movenent ‘= Tine.deltatine;
‘movement = transform. Transforabirect ion(ovement));
__characterController.Move(movenent) ;
}
}