要移动物体,一般是调用UE4内建的寻路API:UNavigationSystem::SimpleMoveToLocation()。
但是如果项目的逻辑比较特殊,想绕开UE4自带的寻路系统的话,一般可以调用:YourActor->GetOwner()->SetActorLocation()。
但是,SetActorLocation()有个问题,如果A点和B点之间有堵墙,使用SetActorLocation(FVector location)的默认参数会穿墙而过,如果想让物体自动在墙的前面挺住,那么再加个参数:Sweep = true,即:SetActorLocation(location, true)。这样就能在改变Location的过程中实现碰撞检测。
FVector Loc = YourActor->GetActorLocation();
Loc.X += 10;
Loc.Y += 10;
YourActor->SetActorLocation(Loc, true);
参考:
https://answers.unrealengine.com/questions/16232/how-to-move-actorsobjects-via-velocity.html