I am trying to spawn enemies at the edge of the camera. But I do not know how to get the edges of the camera as positions. I can get the middle of the screen using `Camera.GetCameraScreenCenter()` and the size of the camera viewport with `Camera.GetViewport().Size`. But since the viewport is in pixels, I do not know how to offset the screen center by 2D units.

Godot version 3.5.1
in Engine

I think when working in 2d the pixels are the units, unless you have done scaling to your nodes.

@magicalogic using your insight, I was able to solve this. If you write your comment as a post, I can mark it as best answer.

just add / subtract half the size to the center to get the edges.

by (8,548 points)

The below code is how I achieved computing camera center and edge position calculations, maybe it can help you:

``````

func computeScreenCenter():
var minPos = computeMinimumPointBoundary()
var maxPos = computeMaximumPointBoundary()
var screenRect = Rect2(minPos,Vector2())
screenRect = screenRect.expand(maxPos)
return calculate_center(screenRect)

func computeMinimumPointBoundary():
# Get view rectangle
var ctrans = getcanvastransform()
var minpos = (-ctrans.getorigin() / ctrans.getscale())
return minpos

func computeMaximumPointBoundary():
# Get view rectangle
var ctrans = getcanvastransform()
var minpos = -ctrans.getorigin() / ctrans.getscale()
var viewsize = getviewportrect().size / ctrans.getscale()
var maxpos = minpos + viewsize
return max_pos

func calculate_center(rect):
return Vector2(
rect.position.x + rect.size.x/2,
rect.position.y + rect.size.y/2)

``````
by (1,080 points)