playMaker

Author Topic: Screen boundaries for player? (2D)  (Read 1545 times)

Haserhud

  • Playmaker Newbie
  • *
  • Posts: 19
Screen boundaries for player? (2D)
« on: January 28, 2020, 06:48:18 PM »
First I want to say thanks to the community for being so incredibly helpful to us beginners.

How do you create screen boundaries for the player in a 2D SHMUP?

I tried first by creating some large invisible sprites with box colliders and made them surround the camera view scene. This does work in that it restricts the player, but it also restricts other objects too. I want ONLY the player to be restricted by the boundaries.

Any suggestions would be greatly appreciated!


Thrump

  • Playmaker Newbie
  • *
  • Posts: 6
Re: Screen boundaries for player? (2D)
« Reply #1 on: January 28, 2020, 08:29:22 PM »
You can achieve this using layers.

Create a new layer called Player and put your player on this layer. You can add and assign layers at the top of a prefab/gameobject in the inspector.

Then assign a new layer to your boundary objects.

Then go to Project Settings window, Physics 2D section. At bottom, look at Layer Collision Matrix. Make sure there's a checkbox for every layer that should collide with your new layers. For the boundary object layer, uncheck for every other layer than the player layer.
« Last Edit: January 28, 2020, 08:30:54 PM by Thrump »

Haserhud

  • Playmaker Newbie
  • *
  • Posts: 19
Re: Screen boundaries for player? (2D)
« Reply #2 on: February 12, 2020, 05:16:52 PM »
You can achieve this using layers.

Create a new layer called Player and put your player on this layer. You can add and assign layers at the top of a prefab/gameobject in the inspector.

Then assign a new layer to your boundary objects.

Then go to Project Settings window, Physics 2D section. At bottom, look at Layer Collision Matrix. Make sure there's a checkbox for every layer that should collide with your new layers. For the boundary object layer, uncheck for every other layer than the player layer.

Thanks Thrump!

Would this also work when using a moving/scrolling camera, or should I use a different method for that?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Screen boundaries for player? (2D)
« Reply #3 on: February 14, 2020, 06:00:33 AM »
Hi,

 you should also learn Cinemachine, you can automate this most likely

Bye,

 Jean