Lua 如何将角色物理移动到亚马逊木材场

Lua 如何将角色物理移动到亚马逊木材场,lua,game-engine,Lua,Game Engine,我在局部空间移动角色物理胶囊时遇到了一些问题。无论我给它什么样的旋转,它仍然相对于世界空间移动。我已经附加了一个网格组件、一个角色物理组件、一个带有输入的输入组件和一个lua脚本。以下是我的lua脚本中的移动代码: function PlayerController:HandleInput(floatValue) local currentBusId = InputEventNotificationBus.GetCurrentBusId() local forwardSpeed

我在局部空间移动角色物理胶囊时遇到了一些问题。无论我给它什么样的旋转,它仍然相对于世界空间移动。我已经附加了一个网格组件、一个角色物理组件、一个带有输入的输入组件和一个lua脚本。以下是我的lua脚本中的移动代码:

function PlayerController:HandleInput(floatValue)
    local currentBusId = InputEventNotificationBus.GetCurrentBusId()

    local forwardSpeed = 0.0
    local sideSpeed = 0.0
    local rotate = 0.0

    local fixedSpeed = self.Properties.Speed * 0.01
    local fixedStrafeSpeed = self.Properties.StrafeSpeed * 0.01

    if(currentBusId == self.forwardBusId) then
        forwardSpeed = floatValue
    end
    if(currentBusId == self.leftBusId) then
        sideSpeed = -floatValue
    end
    if(currentBusId == self.rotateBusId) then
        rotate = floatValue
    end

    PhysicsComponentRequestBus.Event.AddImpulse(self.entityId, Vector3(fixedStrafeSpeed * sideSpeed, fixedSpeed * forwardSpeed, 0.0))
end

我想知道在局部空间中移动角色的最佳方式是什么。

如果希望在局部空间中移动角色,则需要根据角色的方向进行计算。在C++中,它会是:

AZ::Transform myLocation;
TransformBus::EventResult(myLocation, GetEntityId(), &TransformBus::Events::GetWorldTM);

const auto q = Quaternion::CreateFromTransform(myLocation);
const Vector3 disp = q * AZ::Vector3::CreateAxisY( 1.f );
myLocation.SetTranslation(myLocation.GetTranslation() + disp);