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