44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class CharacterMovementCotroller : MonoBehaviour
|
|
{
|
|
|
|
[SerializeField] float driveSpeed = 10f;
|
|
[SerializeField] float turnSpeed = 1000f;
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
EvaluateMovementInput();
|
|
}
|
|
|
|
private Vector3 turnLeft = new Vector3(0, -1, 0);
|
|
private Vector3 turnRight = new Vector3(0, 1, 0);
|
|
|
|
void EvaluateMovementInput() {
|
|
Quaternion currentRotation = transform.rotation;
|
|
if (Keyboard.current.wKey.isPressed) {
|
|
Vector3 moveBy = transform.forward * driveSpeed * Time.deltaTime;
|
|
transform.position += moveBy;
|
|
}
|
|
if (Keyboard.current.sKey.isPressed) {
|
|
Vector3 moveBy = transform.forward * -1 * driveSpeed * Time.deltaTime;
|
|
transform.position += moveBy;
|
|
}
|
|
if (Keyboard.current.aKey.isPressed) {
|
|
transform.Rotate(turnLeft * Time.deltaTime * turnSpeed);
|
|
}
|
|
if (Keyboard.current.dKey.isPressed) {
|
|
transform.Rotate(turnRight * Time.deltaTime * turnSpeed);
|
|
}
|
|
}
|
|
}
|