playMaker

Author Topic: Get camera corners coordinates and spawn between corners  (Read 614 times)

Maya

  • Playmaker Newbie
  • *
  • Posts: 2
Get camera corners coordinates and spawn between corners
« on: January 14, 2024, 08:25:12 AM »
Hi!

I'm making a catcher game and I'm spawning my objects outside of the camera view but always between the top left and right corner. My problem is if the aspect ratio changes, the spawn points don't move with the corners. I don't want to make it for just a specific aspect ratio so I need to find the corners' coordinates of the camera and put my spawn point there.

Please, help me put my spawner points always into the top left and top right corners of the camera with Playmaker!

Thanks!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7619
    • jinxtergames
Re: Get camera corners coordinates and spawn between corners
« Reply #1 on: January 14, 2024, 11:11:26 AM »
there are a few ways to do this,

set some canvas object, set pivot point in top left/right corner and position the object outside the canvas view.
on play use screen to world point to position your spawner.

other way is to get the screen height/width and calculate the ratio.
then depending on the ratio set some pretested position

Maxi

  • Playmaker Newbie
  • *
  • Posts: 41
Re: Get camera corners coordinates and spawn between corners
« Reply #2 on: January 17, 2024, 09:08:38 AM »
Hi,
I think the easiest way would be to use the 'Get Screen Width' Action at the beginning of the game. This would for example be 1920 on a Full HD monitor.

The X value of the right end of the screen is ScreenWidth/2 (= 960) and the left end is (ScreenWidth/2)*-1 (= -960).

When spawning your object you can then use the 'Random Float' action with the left end as Min value and the right end as Max value. Use the resulting float as the X position value of your spawned object action and voilĂ : Your object always spawns within the screen width.

Maya

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Get camera corners coordinates and spawn between corners
« Reply #3 on: January 20, 2024, 03:01:59 PM »
Thanks! It works!