Spawn Actors outside of camera?

Have any questions or problems in making your game, subscribing and/or using our software? Post here.
Forum rules
Make sure you are using the newest version. This can be downloaded at the top of the site via the "downloads" link.

Use a very good subject. "Problem" or "Help" are unacceptable titles.

Use the search feature before posting a question, as the answer is probably already here.

Subscript out of range error 9: This is a generic error, and we'll need way more information than that to figure out the problem. If you get this, strongly consider following the instructions of submitting your project through the Submit Bug feature within the editor.
User avatar
001 Forum Master
Joined: Tue Jul 12, 2011 7:14 am

Spawn Actors outside of camera?

Postby Danny » Thu Oct 22, 2015 1:03 pm

I want to know how to spawn actors 32 pixels outside the cameras edge (32 pixels off screen). This is for a Topdown Map. Thanks :D

User avatar
Ultimate 001 Member
Joined: Tue Sep 29, 2009 10:50 pm
Location: Seattle, Washington

Re: Spawn Actors outside of camera?

Postby RamchuK_Ntertainment » Sun Oct 25, 2015 2:05 pm

Slight mathematics are involved, but nothing lethal.

Firstly, you need to be able to find the camera edge boundaries, which are given to us via '4' simple use values:

Screen.X - Left Camera Edge X-Position
Screen.Y - Top Camera Edge Y-Position
Screen.X2 - Right Camera Edge X-Position (Distance from left map edge IF free camera)
Screen.Y2 - Bottom Camera Edge Y-Position (Distance from top map edge IF free camera)

NOTE: These values are not always per-pixel accurate, in fact, they may be off by exactly 1 pixel, so perfectionists may want to round. Also beware of negatives on Screen.X and Screen.Y, if you plan to allow a free camera from map edge that is.

Given our edge coordinates we can now assume the total territory size that the camera occupies and moreover, we have enough information to do some proper spawning. Assuming you have experience creating actors or using a timer/spawner, I will skip to the actual calculations now.

Whenever you want to spawn an actor somewhere outside of our given camera territory, simply pick an edge (a formula can be written for random edges, but this doesn't give you as much control), match the edge with the corresponding use value that I have mentioned earlier, add or subtract 32, and generate a random value on the opposite axis to the desired extent. In other words, if you want to spawn an actor to the left of the screen (assuming that the screen orientation remains still), use Screen.X - 32 as your X-Coordinate, and Math.Random(Screen.Y,Screen.Y2) as your Y-Coordinate. You can apply further limits.

NOTE: It's a good idea to always check any given coordinates before trying to spawn things there, this is to avoid bugs and errors. The main check should always be one that checks if the provided coordinates are not 'outside' of the map. Something else to consider is checking tile-set obstructions. Creating an actor with the option to reposition if blocked may or may not do the trick.

That is it! :D
Travesty: 3D Survival - WIP >>> Forum Topic
University of Washington (BABA)
-REGT- Ramchuk Entertainment Games Team

User avatar
001 Forum Master
Joined: Tue Jul 12, 2011 7:14 am

Re: Spawn Actors outside of camera?

Postby Danny » Tue Oct 04, 2016 12:00 am

Excellent! Thank you so much for the reply. I will give this a shot. If it works you just helped with Alien Invasions and Random eventz :D

Edit: Come back to this again. Not sure what to do still. :?
Last edited by Danny on Tue Oct 04, 2016 12:01 am, edited 1 time in total.
Reason: Automatically merged double post.

Last bumped by Danny on Tue Oct 04, 2016 12:00 am.

Return to Technical Support Questions

Who is online

Users browsing this forum: No registered users