如果character的胶囊体的collision是无碰撞的,那么你按键盘w键是无法走动的,这个小问题耗费了我两天时间,最后不得一行一行的debug源码才找到。从input到角色移动大概流程如下
APawn::AddMovementInput() 改变了ControlInputVector
APawn::Internal_ConsumeMovementInputVector() 用了ControlInputVector
FVector UPawnMovementComponent::ConsumeInputVector()
{
return PawnOwner ? PawnOwner->Internal_ConsumeMovementInputVector() : FVector::ZeroVector;
}
//在UCharacterMovementComponent::TickComponent()调用了ConsumeInputVector
void UCharacterMovementComponent::TickComponent(.....)
{
..........
const FVector InputVector = ConsumeInputVector();
..........
}
//最后走到UCharacterMovementComponent::PerformMovement
UCharacterMovementComponent::PerformMovement(.....)
{
}
UCharacterMovementComponent::StartNewPhysics(....)
{
}
UCharacterMovementComponent::PhysWalking(......)
{
........
//我就栽在这里了,由于之前代码来回改动比较多,什么时候设置的无碰撞,而自己不知道,所
//以怎么都不走,郁闷+闷气最后只好一行一行查代码,终于找到你这个臭bug
if (!UpdatedComponent->IsQueryCollisionEnabled())
{
SetMovementMode(MOVE_Walking);
return;
}
//没有return下面的代码就是移动角色了,请自行查看
........
}