public float MoveSpeed = 10f;
public float RotateSpeed = 75f;
void Update() {
float vInput = Input.GetAxis("Vertical") * MoveSpeed;
float hInput = Input.GetAxis("Horizontal") * RotateSpeed;
transform.Translate(Vector3.forward * vInput * Time.deltaTime);
transform.Rotate(Vector3.up * hInput * Time.deltaTime);
}
public Vector3 CamOffset = new Vector3(0f, 1.2f, -2.6f);
private Transform _target;
void Start() {
_target = GameObject.Find("Player").transform;
}
void LateUpdate() {
transform.position = _target.TransformPoint(CamOffset);
transform.LookAt(_target);
}
private Rigidbody _rb;
void Start() {
_rb = GetComponent<Rigidbody>();
}
void FixedUpdate() {
Vector3 rotation = Vector3.up * hInput;
Quaternion angleRot = Quaternion.Euler(rotation * Time.fixedDeltaTime);
_rb.MovePosition(transform.position + transform.forward * vInput * Time.fixedDeltaTime);
_rb.MoveRotation(_rb.rotation * angleRot);
}