[JASS] GetCameraTargetPositionX/Y

Status
Not open for further replies.
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
 
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
 
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.
Back
Top