如果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下面的代码就是移动角色了,请自行查看
........
}
本文详细记录了一个关于游戏角色无法移动的问题排查过程。该问题源于角色的胶囊体碰撞被错误地设置为无碰撞状态,导致玩家输入无法转换为移动指令。通过逐行检查代码最终定位到了问题所在,并给出了修复建议。
&spm=1001.2101.3001.5002&articleId=115367926&d=1&t=3&u=9235b18ef2934bd8a72130e5b18c0abe)
694

被折叠的 条评论
为什么被折叠?



