UE4学习笔记16th

来源:互联网 发布:抓鬼软件 编辑:程序博客网 时间:2024/05/16 05:47
 这一节对PawnMovementComponent进行编辑,确定响应。

首先打开PawnMovementComponent.h添加如下代码:
public:
virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
 

在PawnMovementComponent.cpp中定义它:
//Make sure that everything is still valid, and that we are allowed to move.
if (!PawnOwner || !UpdatedComponent || ShouldSkipUpdate(DeltaTime))
{
return;
}//

//Get (and then clear) the movement vector that we set in ACollidingPawn::Tick
FVector DesiredMovementThisFrame = ConsumeInputVector().GetClampedToMaxSize(1.0f) * DeltaTime * 150.0f;
if (!DesiredMovementThisFrame.IsNearlyZero())
{
FHitResult Hit;
SafeMoveUpdatedComponent(DesiredMovementThisFrame, UpdatedComponent->GetComponentRotation(), true, Hit);

//If we bumped into something, try to slide along it
if (Hit.IsValidBlockingHit())
{
SlideAlongSurface(DesiredMovementThisFrame, 1.f - Hit.Time,Hit.Normal,Hit);
}
}


 

ConsumeInputVector(),获取移动向量
SafeMoveUpdatedComponent,处理移动
SlideAlongSurface,处理阻挡
0 0
原创粉丝点击