• 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] camera problems

Status
Not open for further replies.
Hello everyone!
I am having some problem with my camera system. My library looks like this:

JASS:
library Camera initializer Init
    globals
        private timer T = CreateTimer()
        
        constant real  MIN_DISTANCE     = 250
        constant real  MAX_DISTANCE     = 6500
        real array     CAM_DISTANCE[6]
        boolean        CAN_CONTROL      = false

        unit           LockUnit
        real           CameraLockX      = 16448.
        
    endglobals
    
    private function callback takes nothing returns nothing
        local integer i = 0
        
        if CAN_CONTROL == false then
            call SetCameraTargetController(LockUnit, 0, 0, true)
            call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, 270., 0)
            call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, 2600., 0)
            call SetCameraField(CAMERA_FIELD_ROTATION, 90., 0)
        else
            loop
                exitwhen i > 6
                if GetLocalPlayer() == Player(i) then
                  call SetCameraField(CAMERA_FIELD_ZOFFSET, CAM_DISTANCE[i], 0 )
                  call SetCameraField(CAMERA_FIELD_FARZ, 10000.00, 0 )
                endif
                set i = i+1
            endloop
        endif
    endfunction
    
    private function Init takes nothing returns nothing
        local integer i = 0
        
        set  LockUnit = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'h00G', CameraLockX, 548., 90)
        call TimerStart(T, 0.10, true, function callback)
        
        loop
            exitwhen i > 6
            set CAM_DISTANCE[i] = 900
        endloop
    endfunction

endlibrary

Before you say anything, i KNOW i don't have to set camera target every loop, i am just to lazy to look up everywhere i change the CAN_CONTROL variable and put it there. I also know that capital letter names are for constants, but sloppy and inconsistent is just the way i am.

NOW here's my problem:
I have a custom destructable-based menu that you use before the game starts. It is for this one that i have to set wether player can control camera or not. As you can see, the two options also have different camera heights.

This all works well the first time, but:

a) when i go back to the menu (set CAN_CONTROL = false), the camera distance is all wrong and too far away.

b) when i scroll while CAN_CONTROL = true, the camera goes down to normal height again.

I seriously don't know what is wrong here, so please help me out!
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
I suggest you create two cameras, make their properties exactly the same but set the other camera's x or y coordinate to about +0.5 greater than the first one's coordinate. Don't use a dummy unit.

JASS:
library Camera initializer Init
    globals
        private timer T = CreateTimer()
        
        constant real  MIN_DISTANCE     = 250
        constant real  MAX_DISTANCE     = 6500
        real array     CAM_DISTANCE[6]
        boolean        CAN_CONTROL      = false

        unit           LockUnit
        real           CameraLockX      = 8.
        
    endglobals
    
    private function callback takes nothing returns nothing
        local integer i = 0
        
        if CAN_CONTROL == false then
            call CameraSetupApply(gg_cam_c1, true, true)
            call CameraSetupApplyForceDuration(gg_cam_c2, true, 1)
        else
            loop
                exitwhen i > 6
                if GetLocalPlayer() == Player(i) then
                  call SetCameraField(CAMERA_FIELD_ZOFFSET, CAM_DISTANCE[i], 0 )
                  call SetCameraField(CAMERA_FIELD_FARZ, 10000.00, 0 )
                endif
                set i = i+1
            endloop
        endif
    endfunction
    
    private function Init takes nothing returns nothing
        local integer i = 0        
        call TimerStart(T, 0.10, true, function callback)
        loop
            exitwhen i > 6
            set CAM_DISTANCE[i] = 900
        endloop
    endfunction

endlibrary
 
What are the benefits of that?
I used to have a trigger that applied certain camera settings every x seconds, and back then i still had the problem. There's also the fact that the camera wouldn't be properly "locked", you can still kinda sway it towards the sides, if so for an extremely brief moment. It was PurplePoot who adviced me to change into a dummy unit after experiencing this.
 
call SetCameraField(@CAMERA_FIELD_ZOFFSET@, CAM_DISTANCE[i], 0 )

Is that part intentional or not? If it is not intentional, then that might be where your problem lies. Judging by your code, the normal camera is bird's eye facing downward. I think the problem is that with the normal camera, you adjust the z-offset. When you go to the game menu camera, you adjust the target distance. Since no change is made to z-offset when you are viewing the game menu, I assume that it screws up your camera. You can probably fix it just by setting the z-offset to the value you want it to be when the game menu camera is up. (or adjust the distance or w/e method you want)
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
What are the benefits of that?
I used to have a trigger that applied certain camera settings every x seconds, and back then i still had the problem. There's also the fact that the camera wouldn't be properly "locked", you can still kinda sway it towards the sides, if so for an extremely brief moment.

That's why I'm using to camera setups which are almost identical. The camera can't be moved/swayed with arro keys/mouse. It remains locked.

Actually, I should code a public resource for this.
 
Status
Not open for further replies.
Top