Download

Best practices for moving a Pawn within a restricted area.

I’m trying to learn by creating a simple pong clone and so far I’m not doing well.
I have a simple Pawn Class as my PlayerPawn.

In the blueprint which inherits my Pawn class I added a simple box as visual representation.
Now I am moving it on one axis with the “MoveRight” event, which is kind of working.

In the MoveRight method I get the current Location of the Actor, add the value of movement and set the new Location of it using SetActorLocation.

But I also want to constrain the movement to a specific area, for example, a simple square on the ground, and I should not be able to move out of it.
I tried adding blocking objects around the edges, but it appears that setting the location ignores me all blocking elements, I can just “fly” through them.

I feel like in generally this is the wrong approach to move the Pawn.
The controls feel mushy when using the mouse and I don’t know if MoveRight already calculates in deltatime, does it behave the same on different framerates?

I thought about moving things manually in the Tick method instead.
For the restricted area I would just check if the actor is in a certain range and just resetting its position if it goes out of bounds instead.

What is the usual way of doing something like this?

You need to set the ‘sweep’ option to TRUE on the Set Actor Location node for it to collide with Blocking Volumes (or similar invisibile geometry) when moving. If you want to limit to a simple area like a box, you could just manually clamp your position before calling Set Actor Location.

Axes do not include delta time, you need to take that into account if necessary, but you can use the Get World Delta Seconds node. You can see an example in the templates.