[Solved] Individual Camera in THNK

How do I…

Make individual cameras for each player using THNK?

What is the expected result

Have cameras follow each player individually in their client, like in games such as Among Us

What is the actual result (Youtube Video Link)

The cameras just not following the player at all, no matter what different events I try
(Also, for some reason an extra player object is being created when it shouldn’t)

Related screenshots

These are my events at the moment:

I tried to create a separate object for the camera instead of directly the player and linking them, I tried adding the camera behavior to the player (which works, but the camera isn’t individual), but nothing seems to really work

If anyone has an alternative solution to this, please let me know and I’ll try it!

Thank You For Reading!

In your code, only the server know which player objects belong to who. On the client, there is not one picked player, so as per how gdevelop works, since the camera is a free action, the oldest object is used by default, centering on that one.

So what you need to do is:

  • Add a way for the server to tell the client which object is “theirs”
  • Pick that object on the client before centering the camera on a player

To communicate with the players, a server uses state. Since the state is player specific, you will want to use a PlayerState variable, which only gets synced with one specific player.

On the server, when the object is created, set the object variable PlayerState[THNK::PickedPlayer()].Own to true. This is assuming you are creating the object when reacting to a THNK event like “Player Connection” which appropriately sets the picked player to the player that connected. That object variable will only be set for them.

On the client, add a condition PlayerState.Own is true to only pick the object that had this flag set by the server.

1 Like