Get Position of Player's Camera

Status
Not open for further replies.
Level 6
Joined
Sep 19, 2005
Messages
169
How do you do this? I need to get the location that a player is viewing and save it as a point. Basically I'm trying to make a system so that players can view what other players are looking at, but I don't know how to get the position of a player's camera.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,272
If such a system is possible, it will have a huge net traffic load as you would have to continiously stream the other player's camera movements. Thus watch out for lag.

It may be possible as there appears to be natives which return the camera target and angle (I assume). The only problem would be that you need to manually syncronize the values as they would work only for the local player,
 
Level 11
Joined
May 31, 2008
Messages
698
This shows how you can detect where a players mouse is on the map. Probably the closest thing your gonna find

http://www.thehelper.net/forums/showthread.php/38300-How-to-Use-Trackables
(Make sure you read all of it, it says it cant be used for multiple players, but further down it explains how you can use it for multiple players

By the looks of it, you would have to create a ton of these trackers all around your map tho
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
  • Camera Track
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Custom script: if GetLocalPlayer() == GetEnumPlayer() then
          • Set PointArray[(Player number of (Picked player))] = (Target of current camera view)
          • Custom script: endif
This will get each player's camera viewing location and assign it to point array. It leaks,though.
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
  • Camera Track
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Custom script: local real x
      • Custom script: local real y
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Custom script: if GetLocalPlayer() == GetEnumPlayer() then
          • Custom script: set x = GetCameraTargetPositionX()
          • Custom script: set y = GetCameraTargetPositionY()
          • Custom script: endif
          • Custom script: set udg_PointArray[GetPlayerId(GetEnumPlayer()) + 1] = Location(x,y)
I guess this shouldn't desync since no handles are created locally.
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,272
That will also desync as the locations are not syncronized... That is if it does not cause a desync due to the trigger thread crashing as you did not initialize the locals to a value and for players other than player 0 it will be making a Location atleast once with uninitalized locals.

You need to syncronize the X/Y values between all players before they can be correctly and safly used for things like camera mimic.
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
  • Camera Track
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Custom script: local real x
      • Custom script: local real y
      • Custom script: local real x2
      • Custom script: local real y2
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Custom script: if GetLocalPlayer() == GetEnumPlayer() then
          • Custom script: set x = GetCameraTargetPositionX()
          • Custom script: set y = GetCameraTargetPositionY()
          • Custom script: endif
          • Custom script: set x2 = x
          • Custom script: set y2 = y
          • Custom script: set udg_PointArray[GetPlayerId(GetEnumPlayer()) + 1] = Location(x2,y2)
>___________>
Would this desync?
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
It won't desync as is (update). But the location then holds different coordinates for each client and can therefore not be used to create a unit on it for example. The unit would spawn at different positions, having different influences on the game.

There is no need to use an array since you only want to store one location per client, the data won't be distributed to the other ones. And yes, the code will halt at x2 = x but nevermind you do not want the false players to continue anyway. And For Each Player-loops are executed in another function, so you should declare local variables in there.

@Dr Super Good: Camera work is actually asynchronous.

edit: It won't desync as it is only because each client gets exactly one location (given everyone is in All players). Else you would dsync the handle id stack through this halting.

edit2: I have not seen a proper method to broadcast local information to other players yet. Only that you may use SyncStoredInteger and alike of GameCache but you cannot specify which player the others shall take from. Instead that one with fastest access will rule. I have also read about globals being automatically synced by the game but could not reproduce it and you would likewise not be able to define the player.
 
Last edited:
Level 6
Joined
Sep 19, 2005
Messages
169
I'm really not trying to emulate a camera for another player, rather just pan to the location of the first player's camera. As per Water's post, would the above system work because rather than creating a unit which everyone has to see it's just changing the camera for a particular player... thus seen by one player and not causing the desync?
 
I'm really not trying to emulate a camera for another player, rather just pan to the location of the first player's camera. As per Water's post, would the above system work because rather than creating a unit which everyone has to see it's just changing the camera for a particular player... thus seen by one player and not causing the desync?

Sadly, it wouldn't work. If you perform that trigger, it will probably stop the trigger. (because you are creating a location of two uninitialized variables) But anyway, even if you did initialize the variables, it would set the camera to (0,0) rather than the player's camera you want it to.

I suggest that if it is some sort of RPG or something, have it follow that player's hero/units instead. :)
 
Level 13
Joined
Jun 9, 2009
Messages
1,135
hmm, man, you can try few things. F.E. Every 0.03 save camera's point (X,Y) and set variables, far Z , angle of attack, distance to target etc... and you'll get 100% same camera of other player. :)
But you can lock camera to target, and it would always move to that unit without any problems. I hope it helped anyway
 
Status
Not open for further replies.
Top