1
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITKit;
|
||||
using Lightbug.Utilities;
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
@@ -15,20 +16,15 @@ namespace BITFALL.Scenes
|
||||
[SerializeField] private float mass;
|
||||
[SerializeField] private Animator animator;
|
||||
[SerializeField] private RigidbodyComponent rigidbodyComponent;
|
||||
private Vector3 currentPosition;
|
||||
private Quaternion currentRotation;
|
||||
private readonly DoubleBuffer<Vector3> currentPosition=new();
|
||||
private readonly DoubleBuffer<Quaternion> currentRotation=new();
|
||||
private void Start()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if(EditorApplication.isPlaying is false)
|
||||
return;
|
||||
#endif
|
||||
rigidbodyComponent = gameObject.AddComponent<RigidbodyComponent3D>();
|
||||
var transform1 = transform;
|
||||
currentPosition = transform1.position;
|
||||
currentRotation=transform1.rotation;
|
||||
rigidbodyComponent.UseGravity = false;
|
||||
rigidbodyComponent.Mass = mass;
|
||||
rigidbodyComponent = RigidbodyComponent.CreateInstance(gameObject);
|
||||
}
|
||||
private void FixedUpdate()
|
||||
{
|
||||
@@ -36,15 +32,16 @@ namespace BITFALL.Scenes
|
||||
if(EditorApplication.isPlaying is false)
|
||||
return;
|
||||
#endif
|
||||
rigidbodyComponent.Velocity = animator.velocity;
|
||||
rigidbodyComponent.AngularVelocity = animator.angularVelocity;
|
||||
rigidbodyComponent.MoveAndRotate(currentPosition,currentRotation);
|
||||
if(currentPosition.TryGetRelease(out var position))
|
||||
rigidbodyComponent.Position = position;
|
||||
if(currentRotation.TryGetRelease(out var rotation))
|
||||
rigidbodyComponent.Rotation = rotation;
|
||||
}
|
||||
private void OnAnimatorMove()
|
||||
{
|
||||
animator.ApplyBuiltinRootMotion();
|
||||
currentPosition = animator.rootPosition;
|
||||
currentRotation = animator.rootRotation;
|
||||
animator.ApplyBuiltinRootMotion();
|
||||
currentPosition.Release(animator.rootPosition);
|
||||
currentRotation.Release(animator.rootRotation);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user