如何在 Amazon Lumberyard 中在本地移动角色物理

我尝试在本地空间中移动一个角色物理胶囊体,但无论我给它什么旋转,它仍然相对于世界空间移动。我已经添加了一个网格组件、一个角色物理组件、一个输入组件来接收我的输入,还有一个 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

我想知道在本地空间中移动它的最佳方式是什么。

点赞
用户6073249
用户6073249

如果你想在本地空间移动一个角色,那么你就需要根据角色的方向来计算。在 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);
2019-04-27 01:46:07