Author Topic: 3rd Person Camera setup help  (Read 2927 times)

JamminGames

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
3rd Person Camera setup help
« on: June 04, 2013, 12:19:11 AM »
So moving from single player to networked, i'm having some issues (probably my own stupidity) setting up my camera follow script.
Here's how i'm trying to implement it :

 the game scene client side has a camera that exists on level load. my follow script is attached but disabled by default.
when a player joins a match, in that player's start function i get a reference to that camera, and
if (tno.isMine)
{
    playerCam.enabled = true;
    playerCam.GetComponent<ThirdPersonCamera>().createTarget(transform);
}

in my camera script i have a function that takes in a transform and sets its target to look at as that transform and its position attempts to be behind that transform by <distanceOffset> units,

but passing it the transform when a player is created doesn't seem to work. I debug logged on the camera in its create target function what the transform is, and it seems to get a reference to the player object just fine with this method.

Any thoughts?
Should i be using a create for the camera when player is created? My thinking was that i would run into issues having to check for other cameras and delete them client side, since technically only 1 camera is needed per client.

thanks in advance for help :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 3rd Person Camera setup help
« Reply #1 on: June 04, 2013, 05:59:48 PM »
Depending on how this object is created it may not know what "playerCam" is. I recommend using singletons for this. Keep a script on your camera with a public static reference to itself that's set in Awake() -- this way you can use this class from anywhere.

JamminGames

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: 3rd Person Camera setup help
« Reply #2 on: June 05, 2013, 01:43:42 AM »
it's not so much an issue of accessing the camera script, i can either grab a get component reference, or make it a static and access its instance that way. the issue is the fact that the target is supposed to be passed by the player that has just been created, and in the player class it checks if it owns itself, and if it does, it passes its transform to the camera.

this works for first player but not further.

Static class reference, in my understanding, doesn't change the issue of my problem, it simply removes the need for storing a local reference and using the awake() to get its component.
my issue lies more in getting a reference to the player of that client.

i understand that player ID's are unique and in the TNManager script there is a list of all players... could i use that information to access the gameObject of that player and then use its transform.position ?

JamminGames

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: 3rd Person Camera setup help
« Reply #3 on: June 05, 2013, 01:53:34 AM »
like, to clarifiy, in my createTarget(Transform tar) {

}

script i print out what tar is, and in the editor version this works fine, in the build version, if i open up my console and check, it does indeed print out GamePlayer(clone) as something that exists... but it just doenst seem to access it properly

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 3rd Person Camera setup help
« Reply #4 on: June 06, 2013, 07:06:41 AM »
I am not quite understanding your issue here then. "Target is supposed to be passed by the player" -- how is it supposed to be passed? In that snipplet of code you pasted? The way I would do it is like so:

  1. void Start() { if (!TNManager.isConnected) OnNetworkJoinChannel(); }
  2.  
  3. void OnNetworkJoinChannel () { ThirdPersonCamera.instance.target = transform; }

You can find any TNObject by its ID via TNObject.Find. Once you have the TNObject you can get its gameObject or transform, and do what you wish.

JamminGames

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: 3rd Person Camera setup help
« Reply #5 on: June 12, 2013, 03:18:53 AM »
thank you, TNObject.Find is extremely useful.
i was just going about solving the problem in a silly way. It's working fine now I appreciate pointing me in the right direction :)