Will you camera move? Will the character never stray from the center? An easy way to approach it is to get the character location and add 4 Vectors that point out to the 4 circles.
If you want to get more fancyyou have to store 4 directional unit vectors and use some calculations based on the distance between the camera and the character, and the FOV etc, to calculate how LONG the vectors needs to be.
In world coordinates, screen is a small rectangle near the camera. Its size and location depends on near clip plane distance, fov and aspect ratio. So deproject function returns location that is almost equal to camera location.
Real world location of screen edge depends on its depth.
In case your game is a kind of scroller, your character (and enemies) will move in some constant depth from camera.
Usually, NearClipPlaneDist = 10. This is depth of the screen, and its world location will be:
In case your character not moves in constant depth (terrain, slopes, ladders), it is better to make line trace from camera location in 4 directions of screen edges. It should be calculated like:
Thanks, that pointed me in the right direction!
I solved it doing a LineTrace with start = camera location and end = end point of extended vector from camera location to deprojected point on near plane
I get world coordinates on the floor now, which is what i wanted.
Hi, I’d like to spawn actors at the edges of a camera’s viewport, so that it can barely “see” them.
I am using the Top Down template, so it’s a perspective camera. Below is a simplified drawing of what it should look like:
Actors should be spawned at the locations where the circles are.
As I know the screen coordinates of these points, I tried putting them into “deproject from screen to world”.
The resulting world coordinates are all very close to the bottom circle.
Any idea how to solve this?
Hi guys, I would like to drop here my solution. Below method calculates four vertices of camera facing rectangle in world space, that is aligned with viewport edges and fills it entirely. You can specify distance at which you would like to have your rectangle calculated. I’ve added this method to my camera actor.
The default distance of 100u is the currently predefined distance of near clipping plane. Offsets allow to scale rectangle, which helped me to get rectangle slightly bigger than viewport, which I needed to safely fit backgrounds of my 2d game within viewport.
With this you can check if any of your actors are outside of the rectangle bounds on it’s plane at any given distance from camera.