playMaker

Author Topic: Camera tracking a Spawned character...  (Read 5782 times)

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
    • View Profile
Camera tracking a Spawned character...
« on: February 04, 2013, 03:38:33 PM »
Hi!

I have a character and camera controller I am trying out for my game, nearly perfect, a few issues, but... (Hell, Ill ask right out, suggestions for good RPG camera controllers, with smooth follow..? DANG I seem to have tried hundereds.. all are flawed, or too complex)
Anyhoo Where was I?...

So this set up requires that the camera knows where the player is, so you need to drag the player prefab into the slot on the camera script, and now bingo! the camera follws the charater..

EXCEPT, my character is spawned into the game, via the Photon multiplayer stuff... so it doesnt exist in the Hierarchy window till you hit play. So the camera thinks its missing and causes a game pause...

I have tried this: I made a GO, in the scene, called it CameraTracker, dragged THAT into the camera script as the focal point... THEN I added a FSM to it telling it to set its position by a variable. I then added a FSM to my Player Prefab, which Shouted out a global vector3 as THAT variable...

Sort of worked, but, the camera needs to get back behind the charater, and this method only got it pointing at the player. Great for a Side Scroller, but not for this.

Any Ideas how I could do this, either by altering my method (Is there a... um thing that displays rotation as well as position?)
Or some other more sneaky clever clogs way?

 :)

Mark


Andrew.Lukasik

  • Full Member
  • ***
  • Posts: 134
    • View Profile
    • my twitter @andrewlukasik
Re: Camera tracking a Spawned character...
« Reply #1 on: February 04, 2013, 04:53:16 PM »
Hi,
 You can try making two targets for camera to follow:
1st behind Player (parented to his spine bone for example) which camera would follow with action <Move Towards>. I recommend setting its speed as a square of distance to this point + N (because then it will speed up^2 when far away and N will help tweak behavior when close).
2nd target you can put somewhere in front of Player - this would be followed using something like <Smooth Look At>

 And this camera should be idle till Players spawns and broadcasts its existence and data (<GameObject Changed>, <Set Event Data>, <Get Event Info> and Global Variables probably will be usefull here).

A.
« Last Edit: February 04, 2013, 04:57:47 PM by Andrew_Raphael_Lukasik »

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
    • View Profile
Re: Camera tracking a Spawned character...
« Reply #2 on: February 05, 2013, 06:26:08 AM »
Some interesting points here, you are giving me some clues.. but I think you are misunderstanding me a bit.
I already have the camera follow scripting down, it comes as part of this RPG character controller package, and works well. My ONLY problem is that if needs a reference to the player, that doesnt exist yet (infact it could be one of 4 different players)

Using this Camera Tracker GO is working, but only in 2D, itrs not telling the script which way the character is facing, therfore the camera is just following the character, back and forth and not around him. The smooth following is all nice and done in the script, including distance controller by mouse wheel etc... I WILL want to change a little of its functionality later (Id like the char model to disappear completly when fully zoomed in, become a FPS character in other words..)

Mark

Andrew.Lukasik

  • Full Member
  • ***
  • Posts: 134
    • View Profile
    • my twitter @andrewlukasik
Re: Camera tracking a Spawned character...
« Reply #3 on: February 05, 2013, 11:20:02 AM »
Ah excuse me then, misunderstood.
Answering that
Quote
problem is that if needs a reference to the player, that doesnt exist yet (infact it could be one of 4 different players)
I would say that It probably can be done by FSM on that object which would be a event/data receiver and will propagate to this script Player's position etc. by <Set Property>.
 But what about Player+his camera rig as one prefab? This probably would be easier to do. Because then only one Player-prefab can be like that
Quote
itrs not telling the script which way the character is facing
<Smooth Look At> doesn't work with that script?

A.

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
    • View Profile
Re: Camera tracking a Spawned character...
« Reply #4 on: February 06, 2013, 01:41:48 AM »

I would say that It probably can be done by FSM on that object which would be a event/data receiver and will propagate to this script Player's position etc. by <Set Property>.
 But what about Player+his camera rig as one prefab? This probably would be easier to do. Because then only one Player-prefab can be like that
Im not completely understanding this, I have never used event/data receiver before, is this an action? (at work now cant check)

Quote
<Smooth Look At> doesn't work with that script?

may do... but as the scripts already works out of the box, Id rather not add another layer of code, just to botch a fix... better to fix the problem so the script works?
Quote
But what about Player+his camera rig as one prefab? This probably would be easier to do. Because then only one Player-prefab can be like that

Well I tried that, but there was a problem with that too... Cant quite remember what it was, maybe Photon thru a wobbler at the fact that the player was not seen directly in the resources folder, it was something like that... Ill check...

thanks for you help

Mark


A.

Andrew.Lukasik

  • Full Member
  • ***
  • Posts: 134
    • View Profile
    • my twitter @andrewlukasik
Re: Camera tracking a Spawned character...
« Reply #5 on: February 06, 2013, 06:24:00 AM »
Quote
Im not completely understanding this, I have never used event/data receiver before, is this an action?
Yes these are actions. In Player's starting state you fill needed fields in action <Set Event Data> and Send Event "Player Spawned" (by Broadcasting it for example).
To make receiving object you must simply make FSM with Global Transition "Player Spawned" in start of which is a state with <Get Event Info> action. So this is how you can get all variables sent by Player.
Next step it to propagate them to script that controls your camera. You do this by action <Set Property>
« Last Edit: February 06, 2013, 06:25:49 AM by Andrew_Raphael_Lukasik »

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
    • View Profile
Re: Camera tracking a Spawned character...
« Reply #6 on: February 06, 2013, 06:44:22 AM »
Looks good, sure I will use this, but just to confirm, my camera code simply has a slot where I must drag my character, entitled Target.
It is THIS reference that the Camera uses to track its movement and rotation.

The only problem is that because my player is spawned into the game, it doesnt exist (yet) in the Hierarchy. Infact when it arrives its called Bob(Clone), whein reality its called simply Bob.

Will this be fixed using your solution, Im going to dive in and see anyway, but time is limited, dont want it to be a dead end...

again, thanks for your help... you are giving me lots to look into!

PlayMaker is becoming clearer and more exiting everyday!

Mark

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
    • View Profile
Re: Camera tracking a Spawned character...
« Reply #7 on: February 06, 2013, 06:50:51 AM »
Just a bit more info:
When I TRY to add my player to this slot on the camera, Im getting

Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption

Not sure what this means, but.. thats the error im getting!

M

Andrew.Lukasik

  • Full Member
  • ***
  • Posts: 134
    • View Profile
    • my twitter @andrewlukasik
Re: Camera tracking a Spawned character...
« Reply #8 on: February 06, 2013, 09:37:51 AM »
Quote
Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption
This mean that you're trying to set Prefab (from Project), not a instance of it, as a target. I.e.: Camera can't follow target that resides in Project files (ofc)

Andrew.Lukasik

  • Full Member
  • ***
  • Posts: 134
    • View Profile
    • my twitter @andrewlukasik
[source file] boxxy knight and tpp camera rig 01.unitypackage
« Reply #9 on: February 06, 2013, 12:40:47 PM »
Check this tpp camera rig (attachment).
When speaking about camera that spawns with main player I meant something like this. Camera's FSM in this example is responsible for animating it's owner, but you can easily replace it with your own camera script.
« Last Edit: February 07, 2013, 04:36:23 AM by Andrew_Raphael_Lukasik »

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
    • View Profile
Re: Camera tracking a Spawned character...
« Reply #10 on: February 07, 2013, 07:50:53 AM »
Thanks for that Andrew, I can see how you are doing it on your Knight. But this wont work for me because you camera IS parented to the character. I had forgotten WHY I couldn't do this, but its of course because that my game is multiplayer, and of course if the camera is built into the character prefab then many cameras get spawned.
Infact the only camera you want is on the character YOU are controlling.

So the way I am trying is for my character to havea get position and a get rotation action, saving them as Globals, then on the "camera tracker" GO FSM, I have Set Positin and Set Rotation.. The Position is working (I can see the GO sliding around with the character) but when the character rotates, the GO doesn't, so thats really my only problem, why its not rotating...

Mark

Andrew.Lukasik

  • Full Member
  • ***
  • Posts: 134
    • View Profile
    • my twitter @andrewlukasik
Re: Camera tracking a Spawned character...
« Reply #11 on: February 07, 2013, 09:09:52 AM »
Quote
But this wont work for me because you camera IS parented to the character. I had forgotten WHY I couldn't do this, but its of course because that my game is multiplayer, and of course if the camera is built into the character prefab then many cameras get spawned.
In fact the only camera you want is on the character YOU are controlling.
My initial idea was to make two separate prefabs for players. For example: "Player_you" and "Player_others" and only "Player_you" would be equipped with camera. Then spawning FSM/script would decide which one to spawn (and that "Player_you" can have only one instance).
I never done anything including network yet but I presume that this might significantly simplify process of spawning (because "Player_you" and "Player_others" require different control inputs).

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
    • View Profile
Re: Camera tracking a Spawned character...
« Reply #12 on: February 08, 2013, 01:00:31 AM »
I never done anything including network yet but I presume that this might significantly simplify process of spawning (because "Player_you" and "Player_others" require different control inputs).

Actually no, All that happens is that the transform position and animation state is broadcast to all players, you control one of them, your foes control the others!

It might be time for me to build a controller/camera controller from the ground up, using PlayMaker, as the one that comes with Jeans demo (based on the Photon demo) is pretty basic. I know whey they use it tho, its a DODDLE to set up... it just that its so ODD.. the character jumps in 90degree angles when turning on the spot, there no zoom in or out of camera. But what it does do, works flawlessly, with NEVER ANY errors or issues. ALL Controllers I have found and tried from the Asset Store are quirky, and seem to have one or two things I would have done differently...

Considering Players and Player characters MAKE GAMES I am always surprised that this isnt easier...

(Next game is gonna be a FPS!!!)

M

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14119
  • Official Playmaker Support
    • View Profile
Re: Camera tracking a Spawned character...
« Reply #13 on: February 08, 2013, 01:37:38 AM »
Hi,

 that's the catch, it is such an important feature in games, that I guess it's simply difficult to find the right balance, and therefore it boils down to a simple approach to quickly prototype your game, and then expand on it.

 I don't think there is too much relation between camera control and character as far as it being a network instant or not, the only thing is to not have a camera control when the character gameObject is not "mine", that's all. then, whatever is the camera component, I don't see why it would be more difficult then a regular game since, it's the same thing basically.

Could you elaborate on why it's missing, the camera behavior should part of your player prefab, and simply disabled when the gameObject is created and you check that it's not "mine", that's all there is really, isn't it?


bye,

 Jean

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
    • View Profile
Re: Camera tracking a Spawned character...
« Reply #14 on: February 22, 2013, 08:36:31 AM »
Hi,
the camera behavior should part of your player prefab,

Thats the problem, it itsnt!!!
Because Im using a third party system (trying various systems actually) for character control and camera control. They almost always keep the camera separate from the player, but as the player doesn't exist till runtime, its impossible to provide the reference the camera controller needs to follow the character.

One method that I can get to half work (although with some jerkiness) is to have a CamPos prefab that has set position added, and the player char has an FSM with Get position, the player sends the Vector3 as a Var and the Get Position picks it up. Then I can use the CamPos as the camera reference. However, I cant get the CamPos to rotate as the character does... this is an issue that Im constantly getting and have mentioned in another thread, rotating game objects from a var.. just doesnt work for me...

M