简体   繁体   中英

3rd person controller, allow camera through wall and prevent player

im working for 3rd person fighting game between two characters.

I've setup camera to focus enemy and player in same time like Naruto Ultimate Ninja Storm 4, but when camera collide with wall the view angle will be change and both characters will not appear on screen.

in Naruto Ultimate Ninja Storm 4 there is transparent wall around arena which leave empty space between visible object (wall,rock..) and player but allows camera to pass it.

my problem I don't find method to let the camera pass this transparent wall and stop player to pass it.

I tried to get tag of object in collision and disable collider of object when is camera or vice versa but that allow character also to go tought transparent wall

You should create 3 layers, if you haven't already:

  • Player
  • Camera
  • Wall

Put each GameObject in the corresponding layer, then go to Edit->Project Settings->Physics, scroll to the "Layer Collision Matrix" and uncheck the collisions you don't want to have. In your case, you want the collision between the wall and the player, but you have to uncheck the collision between the camera and the wall.

Also, to make this work correctly, make it so that none of the characters, walls, and camera are separate gameobjects.

This is also very useful to remove any unnecessary collision and boost your game performance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM