• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[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,240
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