Развитие гоночек
This commit is contained in:
1 parent
ec60c47652
commit
b54083521f
532 files changed
+16091
-28231
No files matched your search
@@ -0,0 +1,32 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
namespace Code.Example.Race.Racer.Car
|
||||
{
|
||||
public class CarWheelRotator : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private NavMeshAgent agent;
|
||||
[SerializeField] private Transform[] wheels;
|
||||
[SerializeField] private bool rotateDebug;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
Vector3 wheelRotation;
|
||||
foreach (var wheel in wheels)
|
||||
{
|
||||
if (rotateDebug)
|
||||
{
|
||||
UnityEngine.Debug.DrawRay(
|
||||
wheel.position,
|
||||
Vector3.Project(agent.velocity, agent.gameObject.transform.right),
|
||||
Color.yellow, 900f);
|
||||
UnityEngine.Debug.Log(Vector3.Project(agent.velocity, agent.gameObject.transform.right).magnitude);
|
||||
}
|
||||
|
||||
wheelRotation = wheel.localRotation.eulerAngles;
|
||||
wheelRotation.y = Vector3.Project(agent.velocity, agent.gameObject.transform.right).magnitude * 10f;
|
||||
wheel.localRotation = Quaternion.Euler(wheelRotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user