CREATE YOUR WORLD
Players & Characters: Advanced

Camera Collision Layer

8min

Overview

ZepetoCamera created through ZepetoPlayers can control physical collisions between the camera and game objects through the Camera Collision setting.

Camera Collision is when the camera collides with an object in the scene.

If Camera Collision is set, when the camera collides with an object, it will not be able to move in front of that object, causing the camera to stay in front of the object instead of through it.

Let's take a look at the following two examples.

  • In the screen on the left, Camera Collision is not set, allowing the camera to move freely without being affected by objects around the character or the floor.
  • On the right, Camera Collision is enabled, so the camera will not be able to penetrate walls and floors when it moves.

By enabling Camera Collision, the camera's movement is physically affected, meaning that locations that the player cannot see cannot be illuminated by the camera, which allows for a more realistic depiction.

Document image




Setting up ZepetoPlayers Camera Collision

1) You can set what collision the camera detects per Layer.

  • To set or add a user layer, press the Layer drop-down menu in the Inspector window and select Add Layer.
  • The layers that a user can add can be numbered Layer3 and Layer6 or higher. Layer0 ~ 2 and Layer6 ~ 7 are Unity's default layers.
Document image




2) Select the object you want the camera to apply collision judgment to, and then select the layer you set up.

Document image




3) Now, in the Camera part of ZepetoPlayers, you can select the layer you want to register as a collision by pressing the drop-down button for Collision. Check the layers you have added.

Document image




4) Now press the Play button to run the runtime and you will see that the Zepeto Camera moves through the floor and walls without breaking through them.

Document image




Setting it as a script at runtime

  1. You can specify Camera Collision dynamically at runtime.
  2. below is a script to set the collisionLayer number registered as a public variable as a layer mask at runtime.
  • The key is to specify the layer mask to be selected in ZepetoPlayers.instance.cameraData.layer.
CameraCollisionManager


3. Script description

  • In order to script a layer and apply it to the camera, we need to use a LayerMask.
  • The LayerMask will have a value entered through bitwise operations.
    • The LayerMask is represented as an integer value, where each bit indicates whether the layer is included or not.
    • For example, if the LayerMask has a value of 5 (00000101 in binary), we can say that layer 0 and layer 2 are included.
  • layerMaskValue |=: This bitwise operation combines the existing layerMaskValue and the newly calculated value in an OR operation.
    • If the existing layerMaskValue is 00000001 in binary, and the newly calculated value is 00000100, ORing the two values will result in 00000101 in binary.
    • This ensures that both layer 0 and layer 2 are included in the LayerMask.
  • In the case of EnhancedCamera, the Player layer is not set to the camera’s collision layer to prevent the camera from intersecting with the character.