-1

下午好。我在使用 UnrealScript 编程时遇到了一些问题,我想知道你们中是否有人能够解决我的问题。我可以使用阻塞体积将角色锁定在轴中,但如果必须的话,我想在脚本之前尝试。提前致谢。

4

1 回答 1

1

一种简单的方法可能是将玩家的位置沿轴设置回每个刻度的固定值。由于您想将他锁定在 X 轴上,因此您需要确保他的棋子不会沿 Y 轴移动。

如果您使用的是自定义 PlayerController:

class MyPlayerController extends PlayerController;

simulated event Tick (float deltaTime)
{
    local vector snappedLocation;

    Super.Tick(deltaTime);

    if (Pawn != none)
    {
        snappedLocation = Pawn.Location;
        snappedLocation.Y = 0.0;
        Pawn.SetLocation(snappedLocation);
    }
}

或者,如果您想要的不仅仅是将玩家的 pawn 锁定到 X 轴(假设您也希望将敌人锁定到 X 轴),您可以在 Pawn 的一个或多个子类中实现它:

class MyPawn extends Pawn;

simulated event Tick (float deltaTime)
{
    local vector snappedLocation;

    Super.Tick(deltaTime);

    snappedLocation = Location;
    snappedLocation.Y = 0.0;
    SetLocation(snappedLocation);
}

Depending on what you're trying to do however, you may run into problems with this approach since the player can still turn and his Velocity and Acceleration vectors may not point strictly along the X axis. You could try disabling turning by extending the PlayerInput class and always setting aTurn to zero in the PlayerInput event. A more robust solution may be to do a little more math yourself in PlayerController and make sure that the pawn's velocity and acceleration only ever point along the X axis; check out the PlayerMove function in the PlayerWalking state in PlayerController for an example of how the PlayerController can be used to control a Pawn's motion by changing its acceleration.

于 2012-11-01T00:38:52.440 回答