Hey Guys.
I’ve got a problem with rotation. It looks like the whole objects hitting some kind of barrier.
It looks like this: cmb7d3
And here’s the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
[SerializeField] private float _speed = 4f;
[SerializeField] private float _smooth = 1f;
[SerializeField] private GameObject _Player;
public Quaternion newRotation;
public Vector3 newPosition;
// Start is called before the first frame update
void Start()
{
newPosition = transform.position;
newRotation = transform.rotation;
}
// Update is called once per frame
void Update()
{
MovementController();
}
void MovementController()
{
if (Input.GetKey(KeyCode.W))
{
newPosition += (transform.forward * _smooth);
}
if (Input.GetKey(KeyCode.S))
{
newPosition += (transform.forward * -_smooth);
}
if (Input.GetKey(KeyCode.D))
{
newPosition += (transform.right * _smooth);
}
if (Input.GetKey(KeyCode.A))
{
newPosition += (transform.right * -_smooth);
}
if (Input.GetKey(KeyCode.Q))
{
newRotation *= Quaternion.Euler(Vector3.up * _speed);
}
else if (Input.GetKey(KeyCode.E))
{
newRotation *= Quaternion.Euler(Vector3.down * _speed);
}
transform.position = Vector3.Lerp(transform.position, newPosition, Time.deltaTime * _smooth);
transform.rotation = Quaternion.Lerp(transform.rotation, newRotation, Time.deltaTime * _smooth);
}
}