Download

Clamp Player Movement within Screen View / Screen Edge

Hi,
I’m working on a topdown space shooter game for the mobile device and I need a way
to stop the player ship from moving off the screen.

d929f84d9a5c18b5308470eaa1e38c1038b4ca6b.jpeg

In the Playership actor(pawn blueprint), “SetActorLocation” is used to move the player location and after that
I use this clamp function to limit the movement, but how do I get it work at the screen edge.

This is what I have so far.
At the moment those are just fixed values (-100,100) for the min and max clamp values, but I’m kinda stuck
on figuring out how to get those clamp values from or depending on the screen size

33d705ccaa1736444e42b352edbdfb98790f823f.jpeg

I have tried several ways like getting the screen size (X & Y)and divide those by half and use it for the
min and max clamp values, but no luck
I have failed trying to get this to work since this week !!

.

You can put collision boxes around map which block only your movement… or you cant use this for your project?

I can’t use collision boxes. It has to be based on the screen edges since the screen size would be varying for different devices.

“Project World to Screen” coupd help… Never tested it either…
My idea would be to Project the Position of the Player to screen coordinates, and ask if the player is outside screen width/height…

Hey thanks Chaosgod_Espér, that kinda actually worked, can use it to detect the player at the screen edges :slight_smile:
I setup it up this way
deffa4b2c9c08528c3914d7903e5faf1cf006721.jpeg

.
Now I need is to stop the movement or set the player position to the previous location. Any way to do it ??

.

any way to bump back the player to the previous location within the screen edge?

Ill try this, but can u tell me on which wire is plugged your first sequence ?

Thank a lot, now I’m looking to make my character move with the screen edges when he’s on the end cause the camera is scrolling from left to right

Its a custom function that is connected from the tick event.

Thank you, did you find how to to stop movement when the character reach the border ?

Even tho this is 2 years old, Nobila would need to set the velocity of the movement in that particular direction to zero (for those scoping for answers), cheers!