Download

Moving Object at Runtime Moves it In Level Permanently

Hello,

I am developing an endless run style racing game. If the car gets too far away from origin many bugs happen. So I decided to move all actors towards origin every once in a while.

Lets say my X object is originally at (0,0,0) location. If I move it to (-1000, 0, 0) during gameplay, it stays there even if I stop game, and next time it starts from (-1000,0,0) instead of (0,0,0). Of course this only happens with objects that are not created on runtime.

I move my object like this:



auto NewLocation = CurrentObj->GetActorLocation();
NewLocation.X -= 1000.f;
CurrentObj->SetActorLocation(NewLocation);


I use TObjectIterator<AActor> to iterate over objects and use AActor CurrentObj = Cast<AActor>(Itr); to get the object instance.

What am I missing here?

Thanks.

Use world origin shifting. It adjust world coordinates to stay within float error.

I tried that but for some reason world my player is not at (0,0,0) location after setting world origin to player. This gets accumulated and eventually player gets so far away from origin even with origin shifting. I set my origin like this:



GetWorld()->SetNewWorldOrigin(FIntVector(GetActorLocation()));


This is called from my player pawn.

EDIT: Nevermind, I needed to add + **GetWorld()->OriginLocation. **Now my pawn strangely slides when I shift origin but I guess thats because of my pawn implementation. Thanks for the answer.

EDIT2: Shifting world origin works perfectly fine and better solution to moving actors one by one. Pawn sliding bug was because of my other implementations.