0
votes

Hi I was just wondering what position will take priority with a child objects position. Does the position of the parent object or a position set through a script take priority?

I'm asking this because I have a player with a camera as a child object which by default follows the parent. I'm trying to implement a system where I can set the transform.position of the camera to the other player in the game when you finish, sort of like a spectator mode. The original player that the camera follows is constantly falling when they complete the game as they fall out the map, and I can't destroy the player as it holds information about their score that I need later.

Possibly the constantly moving player (as it falls) is stopping the camera from lerping to the other player in the game?

1
For the behavior you've specified ( spectator mode ) I would suggest you to use a GameObject Target for that particular camera and use that as your main point of the logic. If Target is set ( Target != null ) then follow that particular Target object. If it is not set ( Target == null ) then find another Target and follow that object. - Mateusz
I have a gameobject target for a "followplayer" script attached to the camera however the same camera(s) are also attached as a child of the player they were originally following ( the camera is instantiated with the player ) so all I really need to figure out is how to instantiate the camera without the player but set the target correctly. - Thomas Upson
This really depends on your game mechanics and internals. I would go for the easiest solution, eg. You should have a list of all players which mean that they will have direct reference to the GameObject. Based on that you can just instantiate the Camera object without setting any target and then distinguish which player to attach to ( based on network id or something ). Then when your player dies ( or whatever it takes to "detach" ) just call some method on your Camera behavior to set target to another player or null and the use method to find new target. - Mateusz
Not need to detach or instantiate, just you have your camera player and set active to your player and all other players inactive, like network. - joreldraw
All player have 1, when you die and go spectator, turn off your player camera, and set active camera the other player camera - joreldraw

1 Answers

1
votes

In this case you need to change the parent of the camera to the player you want to follow (since the current parent is constantly changing it's position by falling down). You could also set the rigidbody of the player that is falling to kinematic so it won't move and disable it's renderer so he is not visible.