blob: e339116cbf6847e39b5f534f3c66a524b3348937 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
using System;
using UnityEngine;
public class PlayerRotationController : MonoBehaviour
{
[Range(0, 1)] public float lerpSpeed = 0.25f;
public Transform lookAt;
public PlayerControl control;
private readonly float _len = 5f;
private Vector3 _target;
private void Update()
{
var dir = new Vector3(control.movementHorizontal, 0, control.movementVertical).normalized;
if (dir != Vector3.zero)
{
_target = dir * _len;
// lookAt.localPosition = _target;
}
}
private void FixedUpdate()
{
var pos = lookAt.localPosition;
lookAt.localPosition = Vector3.Lerp(pos, _target, lerpSpeed);
}
}
|