导入leg插件,完成腿部动画
This commit is contained in:
@@ -50,7 +50,7 @@ namespace NBF.Fishing2
|
||||
var unityComponent = self.MapUnit.GetComponent<UnitUnityComponent>();
|
||||
if (unityComponent != null)
|
||||
{
|
||||
var root = unityComponent.Transform.Find("FPSCamera");
|
||||
var root = unityComponent.Asset.FPSCamera;
|
||||
self.Camera.transform.SetParent(root);
|
||||
self.Camera.transform.localPosition = Vector3.zero;
|
||||
self.Camera.transform.localRotation = Quaternion.identity;
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace NBF.Fishing2
|
||||
/// <returns></returns>
|
||||
public static GameObject CreatePlayer(Transform parent)
|
||||
{
|
||||
var model = Resources.Load<GameObject>("Prefabs/Player/male");
|
||||
var model = Resources.Load<GameObject>("Prefabs/Player/Human_Male");
|
||||
return Object.Instantiate(model, parent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,11 +17,12 @@ namespace NBF.Fishing2
|
||||
public bool isMoving; // 是否正在移动
|
||||
public double serverTimestamp; // 服务器时间戳
|
||||
}
|
||||
|
||||
|
||||
public class CharacterControllerComponent : Entity
|
||||
{
|
||||
public bool IsSelf;
|
||||
public CharacterController characterController;
|
||||
public PlayerAsset PlayerAsset;
|
||||
|
||||
public readonly Queue<MoveState> MoveStateQueue = new Queue<MoveState>();
|
||||
|
||||
@@ -39,6 +40,21 @@ namespace NBF.Fishing2
|
||||
public float rotationLerpSpeed = 10f;
|
||||
|
||||
|
||||
private float currentSpeed = 0f;
|
||||
private float acceleration = 10f; // 加速度
|
||||
|
||||
/// <summary>
|
||||
/// 重力加速度
|
||||
/// </summary>
|
||||
private float gravity = 9.81f;
|
||||
|
||||
|
||||
private Vector3 currentVelocity = Vector3.zero;
|
||||
private float verticalVelocity = 0f;
|
||||
|
||||
private float groundedGravity = -0.5f; // 小的向下力确保角色保持在地面
|
||||
private float airControl = 0.5f; // 空中控制系数
|
||||
|
||||
#region System
|
||||
|
||||
public class MoveComponentDestroySystem : DestroySystem<CharacterControllerComponent>
|
||||
@@ -60,6 +76,8 @@ namespace NBF.Fishing2
|
||||
inputComponent.OnPlayerValuePerformed -= self.OnPlayerValuePerformed;
|
||||
}
|
||||
}
|
||||
|
||||
self.PlayerAsset = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,11 +86,13 @@ namespace NBF.Fishing2
|
||||
protected override void Awake(CharacterControllerComponent self)
|
||||
{
|
||||
var unitUnityComponent = self.Parent.GetComponent<UnitUnityComponent>();
|
||||
self.PlayerAsset = unitUnityComponent.Asset;
|
||||
self.characterController = unitUnityComponent.GameObject.GetComponent<CharacterController>();
|
||||
self.lastSyncedFacing = self.characterController.transform.forward;
|
||||
// 初始化目标位置和旋转
|
||||
self.targetPosition = self.characterController.transform.position;
|
||||
self.targetRotation = self.characterController.transform.rotation;
|
||||
self.characterController.enabled = true;
|
||||
var mapUnit = self.Parent as MapUnit;
|
||||
if (mapUnit.IsSelf())
|
||||
{
|
||||
@@ -104,7 +124,6 @@ namespace NBF.Fishing2
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Input
|
||||
|
||||
private void OnPlayerPerformed(string action)
|
||||
@@ -271,19 +290,33 @@ namespace NBF.Fishing2
|
||||
// 检查是否需要自动停止(可选)
|
||||
// 例如基于时间或距离的条件
|
||||
}
|
||||
else
|
||||
{
|
||||
//保持在地面
|
||||
// 处理重力
|
||||
if (!characterController.isGrounded)
|
||||
{
|
||||
verticalVelocity -= gravity * Time.deltaTime;
|
||||
// 组合移动
|
||||
Vector3 totalMovement = currentVelocity * Time.deltaTime;
|
||||
totalMovement.y = verticalVelocity * Time.deltaTime;
|
||||
characterController.Move(totalMovement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void StartMovement(MoveState moveState)
|
||||
{
|
||||
targetPosition = moveState.startPosition;
|
||||
|
||||
PlayerAsset.InputMagnitude = 0.5f;
|
||||
Debug.Log($"开始移动 - 位置: {moveState.startPosition}");
|
||||
}
|
||||
|
||||
private void StopMovement(MoveState moveState)
|
||||
{
|
||||
targetPosition = moveState.startPosition;
|
||||
PlayerAsset.InputMagnitude = 0;
|
||||
Debug.Log($"停止移动 - 最终位置: {moveState.startPosition}");
|
||||
}
|
||||
|
||||
@@ -292,10 +325,44 @@ namespace NBF.Fishing2
|
||||
// 修改:使用世界坐标方向而不是相对坐标方向
|
||||
Vector3 movementDirection = currentMoveState.moveDirection;
|
||||
|
||||
Vector3 movement = movementDirection * currentMoveState.moveSpeed * Time.deltaTime;
|
||||
targetPosition += movement;
|
||||
characterController.Move(movement);
|
||||
float targetSpeed = currentMoveState.moveSpeed;
|
||||
|
||||
// 平滑加速
|
||||
if (movementDirection.magnitude > 0.1f)
|
||||
{
|
||||
currentSpeed = Mathf.Lerp(currentSpeed, targetSpeed, acceleration * Time.deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
currentSpeed = Mathf.Lerp(currentSpeed, 0f, acceleration * 2f * Time.deltaTime);
|
||||
}
|
||||
|
||||
// 处理重力
|
||||
if (characterController.isGrounded)
|
||||
{
|
||||
verticalVelocity = groundedGravity;
|
||||
|
||||
// 地面移动 - 完全控制
|
||||
currentVelocity = Vector3.Lerp(currentVelocity, movementDirection.normalized * currentSpeed,
|
||||
acceleration * Time.deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
verticalVelocity -= gravity * Time.deltaTime;
|
||||
|
||||
// 空中移动 - 有限控制
|
||||
Vector3 targetAirVelocity = movementDirection.normalized * currentSpeed * airControl;
|
||||
currentVelocity = Vector3.Lerp(currentVelocity,
|
||||
new Vector3(targetAirVelocity.x, currentVelocity.y, targetAirVelocity.z),
|
||||
acceleration * Time.deltaTime);
|
||||
}
|
||||
|
||||
// 组合移动
|
||||
Vector3 totalMovement = currentVelocity * Time.deltaTime;
|
||||
totalMovement.y = verticalVelocity * Time.deltaTime;
|
||||
|
||||
// Character.CollisionFlags =
|
||||
characterController.Move(totalMovement);
|
||||
}
|
||||
|
||||
// 添加位置和旋转插值方法
|
||||
@@ -356,7 +423,7 @@ namespace NBF.Fishing2
|
||||
// 检查朝向同步
|
||||
private void CheckRotationSync()
|
||||
{
|
||||
if(!IsSelf) return;
|
||||
if (!IsSelf) return;
|
||||
rotationSyncTimer += Time.deltaTime;
|
||||
if (rotationSyncTimer >= rotationSyncInterval)
|
||||
{
|
||||
|
||||
@@ -29,7 +29,36 @@ namespace NBF
|
||||
#region 动画
|
||||
|
||||
#region 参数定义
|
||||
|
||||
private static readonly int InputHorizontalHash = Animator.StringToHash("InputHorizontal");
|
||||
private static readonly int InputVerticalHash = Animator.StringToHash("InputVertical");
|
||||
private static readonly int InputMagnitudeHash = Animator.StringToHash("InputMagnitude");
|
||||
private static readonly int IsSprintingHash = Animator.StringToHash("IsSprinting");
|
||||
public float InputHorizontal
|
||||
{
|
||||
get => Animator.GetFloat(InputHorizontalHash);
|
||||
set => Animator.SetFloat(InputHorizontalHash, value);
|
||||
}
|
||||
public float InputVertical
|
||||
{
|
||||
get => Animator.GetFloat(InputVerticalHash);
|
||||
set => Animator.SetFloat(InputVerticalHash, value);
|
||||
}
|
||||
public float InputMagnitude
|
||||
{
|
||||
get => Animator.GetFloat(InputMagnitudeHash);
|
||||
set => Animator.SetFloat(InputMagnitudeHash, value);
|
||||
}
|
||||
public bool IsSprinting
|
||||
{
|
||||
get => Animator.GetBool(IsSprintingHash);
|
||||
set => Animator.SetBool(IsSprintingHash, value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private static readonly int StartThrowHash = Animator.StringToHash("startThrow");
|
||||
private static readonly int LureThrownHash = Animator.StringToHash("lureThrown");
|
||||
private static readonly int PrepareThrowHash = Animator.StringToHash("prepareThrow");
|
||||
|
||||
Reference in New Issue
Block a user