using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using SHADE; namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework { public class RotateToVelocity : Script { public float rotationPerSecond = 2.0f; protected override void update() { RigidBody rigid = GetComponent(); Transform transform = GetComponent(); if(rigid && transform) { Vector3 vel = rigid.LinearVelocity; if(vel.GetSqrMagnitude() > 1.0f) { Quaternion currentRotation = transform.LocalRotation; Quaternion targetRotation = Quaternion.Euler(0.0f, MathF.Atan2(vel.x, vel.z), 0.0f); transform.LocalRotation = Quaternion.Slerp(currentRotation, targetRotation, rotationPerSecond * (float)Time.FixedDeltaTime); } } } } }