How to keep 'game world' objects in the same spot on the screen

I want an object in the ‘game world’ layer of the game to move like an object in the ‘user interface’ layer, where it stays stationary in its onscreen location. I can’t have the objects in the UI layer because collisions are not possible in the there. Anyone have any suggestions?

1 Like

You add the camera position to its starting position.

1 Like

This was actually something I had an issue with myself, since I wanted a cursor in the game layer so it was able to read collisions from other objects.

I don’t exactly have an example just for a standard object to stay stationary on the screen, but here is the code below for a cursor that I had made, which compares the mouse movement from the screen, and takes the difference when the camera moves, so it basically follows the camera while also being able to move about the screen as a standard cursor. This way it doesn’t float off screen when the player or camera moves away.

But if you want to have a normal object act as a UI object, like what JR01 has beaten me to, you can take the Camera’s X and Y location and have it set as a base the object is focused on. Then you can use expressions to offset the location to wherever on the screen you want it to be.

1 Like

I like this idea, but how would you deal with the camera approaching the edge of the viewable area? The camera will approach the edge and offset from the original position, causing the other object to be offset as well

1 Like

So, are you wanting an object to go off the screen when the player does or remain locked on the screen even if the player goes beyond the camera’s limits?

For the first one, if the player is stationary near the middle of the screen or the camera follows the player strictly, then you can just use the players location instead of the camera. If you have a following camera that follows the player at a specific speed so it tags along the player and catches up when you stop moving, then it’s more complicated since you have to detect the camera’s X and Y difference to the players X and Y difference so the UI game layer object is still matched with the camera screen.

For the second one, you could just use a filter or something to detect the camera’s Max X and Y coordinate from all four directions. So, if camera x greater than 1000 or less than -1000, then have it turn a switch off, so it stops detecting the camera’s location at that point and just remain fixed on the X axis of the screen like an actual UI object. Then do the same for the Y coordinates as well with whatever the max size is.

1 Like

Sounds good! Thanks for the help ManiacPumpkin and JR01. It has been awhile

1 Like

Find the camera position and save it into a set of Globals.
Then get those globals in the object you want to act like UI and move it relative to the Camera’s coordinates.


In the expression, have B be the number of pixels away from the center, or the camera, you want the object to be on each axis.

Oh, this was already solved. Sorry!

1 Like

That worked! Thanks for the help!

1 Like

Use a script to lock the object’s position relative to the camera, updating its position each frame to match the camera’s movement, keeping it stationary on-screen.

1 Like