27 lines
918 B
C#
27 lines
918 B
C#
using Code.OfficeGame.BattleMode.Actions;
|
|
using KinematicCharacterController;
|
|
using UnityEngine;
|
|
|
|
namespace Code.Game.Entities
|
|
{
|
|
public static class EntityExtensions
|
|
{
|
|
// WC
|
|
public static void SyncRootMotionToMotor(this EntityProperties entity, bool syncRotation = true)
|
|
{
|
|
Transform animTransform = entity.animator.transform;
|
|
KinematicCharacterMotor motor = entity.KinematicCharacterMotor;
|
|
|
|
Vector3 targetWorldPos = animTransform.position;
|
|
Quaternion targetWorldRot = syncRotation
|
|
? animTransform.rotation
|
|
: motor.TransientRotation;
|
|
|
|
animTransform.localPosition = Vector3.zero;
|
|
animTransform.localRotation = Quaternion.identity;
|
|
|
|
motor.SetPositionAndRotation(targetWorldPos, targetWorldRot);
|
|
motor.BaseVelocity = Vector3.zero;
|
|
}
|
|
}
|
|
} |