• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] GetCameraTargetPositionX/Y

Status
Not open for further replies.
Level 16
Joined
Mar 3, 2006
Messages
1,564
I want to make a camera shake option so that when a player scrolls the camera to a certain location the camera will start shaking but I don't know how the function GetCameraTargetPositionXGetCameraTargetPositionY works for multi-player. So far I made something like this:
JASS:
    private function cameraShake takes real x,real y returns nothing
        local real camx = GetCameraTargetPositionX()
        local real camy = GetCameraTargetPositionY()
        local real dx = x - camx
        local real dy = y - camy
        local real dist = SquareRoot( dx*dx + dy*dy )
        if dist <= 500. then
            // Start Shaking the camera
        endif
    endfunction
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
Use GetLocalPlayer, like this for example:

JASS:
    private function cameraShake takes real x,real y returns nothing
        local real dx
        local real dy
        local integer i = 0

        loop
            if GetLocalPlayer() == Player(i) then
                set dx = x - GetCameraTargetPositionX()
                set dy = y - GetCameraTargetPositionY()
                if SquareRoot( dx*dx + dy*dy ) <= 500. then
                    // Start Shaking the camera
                endif
             endif
             exitwhen i == 11
             set i = i + 1
        endloop
    endfunction
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
You do not need it if you do not want to filter the player out. GetCameraTargetPositionX/Y returns different values for different players. So you are fine as long as you do not do something gameplay-relevant within the if-block.

Also, distances can be compared by comparing their squares, so dx*dx + dy*dy <= 500.*500. is fine, saves the relatively slow SquareRoot function call.
 
Status
Not open for further replies.
Top