修改移动控制
This commit is contained in:
@@ -21,6 +21,7 @@ namespace NBF.Fishing2
|
||||
public class CharacterControllerComponent : Entity
|
||||
{
|
||||
public bool IsSelf;
|
||||
public bool Run;
|
||||
public CharacterController characterController;
|
||||
public PlayerAsset PlayerAsset;
|
||||
|
||||
@@ -63,6 +64,7 @@ namespace NBF.Fishing2
|
||||
{
|
||||
self.characterController = null;
|
||||
self.IsSelf = false;
|
||||
self.Run = false;
|
||||
var mapUnit = self.Parent as MapUnit;
|
||||
if (mapUnit.IsSelf())
|
||||
{
|
||||
@@ -130,7 +132,7 @@ namespace NBF.Fishing2
|
||||
{
|
||||
if (action == InputDef.Player.Run)
|
||||
{
|
||||
// Run = true;
|
||||
Run = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +140,7 @@ namespace NBF.Fishing2
|
||||
{
|
||||
if (action == InputDef.Player.Run)
|
||||
{
|
||||
// Run = false;
|
||||
Run = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,23 +181,17 @@ namespace NBF.Fishing2
|
||||
|
||||
Vector3 movementDirection = Vector3.zero;
|
||||
|
||||
// 修改:根据角色当前朝向计算移动方向
|
||||
// 发送本地相对坐标而不是世界坐标
|
||||
if (!isStop)
|
||||
{
|
||||
// 获取角色当前的右向和前向(在水平面上)
|
||||
Vector3 characterRight =
|
||||
Vector3.ProjectOnPlane(characterController.transform.right, Vector3.up).normalized;
|
||||
Vector3 characterForward = Vector3.ProjectOnPlane(characterController.transform.forward, Vector3.up)
|
||||
.normalized;
|
||||
|
||||
// 根据角色朝向计算实际移动方向
|
||||
movementDirection = characterForward * movementInput.y + characterRight * movementInput.x;
|
||||
movementDirection = new Vector3(movementInput.x, 0, movementInput.y);
|
||||
}
|
||||
|
||||
Net.Send(new C2Map_Move()
|
||||
{
|
||||
Direction = movementDirection.ToVector3Info(),
|
||||
IsStop = isStop,
|
||||
IsRun = Run,
|
||||
Timestamp = TimeHelper.Now,
|
||||
Position = mapUnit.Position.ToVector3Info(),
|
||||
Rotation = mapUnit.Forward.ToVector3Info(),
|
||||
@@ -306,8 +302,11 @@ namespace NBF.Fishing2
|
||||
|
||||
private void UpdateMovement()
|
||||
{
|
||||
// 修改:使用世界坐标方向而不是相对坐标方向
|
||||
Vector3 movementDirection = currentMoveState.moveDirection;
|
||||
// 将本地相对方向转换为世界方向
|
||||
Vector3 localDirection = currentMoveState.moveDirection;
|
||||
Vector3 characterRight = Vector3.ProjectOnPlane(characterController.transform.right, Vector3.up).normalized;
|
||||
Vector3 characterForward = Vector3.ProjectOnPlane(characterController.transform.forward, Vector3.up).normalized;
|
||||
Vector3 movementDirection = characterForward * localDirection.z + characterRight * localDirection.x;
|
||||
|
||||
float targetSpeed = currentMoveState.moveSpeed;
|
||||
|
||||
|
||||
@@ -163,6 +163,7 @@ namespace NBC
|
||||
Rotation = default;
|
||||
Direction = default;
|
||||
IsStop = default;
|
||||
IsRun = default;
|
||||
Timestamp = default;
|
||||
#if FANTASY_NET || FANTASY_UNITY
|
||||
GetScene().MessagePoolComponent.Return<C2Map_Move>(this);
|
||||
@@ -180,6 +181,8 @@ namespace NBC
|
||||
[ProtoMember(4)]
|
||||
public bool IsStop { get; set; }
|
||||
[ProtoMember(5)]
|
||||
public bool IsRun { get; set; }
|
||||
[ProtoMember(6)]
|
||||
public long Timestamp { get; set; }
|
||||
}
|
||||
[ProtoContract]
|
||||
|
||||
Reference in New Issue
Block a user