3rd Person Cam Z issue

wellwish3r

wishes wells.
Reaction score
52
Im working on a 3rd person cam system, so far it woks fine except for one thing. The Z elevation of the camera goes way to high when the unit that it is locked on goes on raised terrain. It works fine when walks up standard cliffs, just not on raised terrain... I dont know why.

JASS:
scope Camera initializer Init
    
    struct cam
        unit locked
        real distance
        real angle
        location loc
    endstruct

    globals
        private integer Total = 11
        private cam array D
        private timer T = CreateTimer()
    endglobals

    private function TimerLoop takes nothing returns nothing
        local integer i = 0
        local real z
        loop
            exitwhen i>=Total
            if D<i>.locked != null then
                set D<i>.loc = GetUnitLoc(D<i>.locked)
                set z = GetLocationZ(D<i>.loc)
                if (GetLocalPlayer() == Player(i)) then
                    call PanCameraToTimed(GetLocationX(D<i>.loc), GetLocationY(D<i>.loc), 1)
                endif
                if (GetLocalPlayer() == Player(i)) then
                    call SetCameraTargetController(D<i>.locked, 0, 0, false)
                endif
                if (GetLocalPlayer() == Player(i)) then
                    call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, D<i>.distance, .75)
                endif
                if (GetLocalPlayer() == Player(i)) then
                    call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, D<i>.angle, .75)
                endif
                if (GetLocalPlayer() == Player(i)) then
                    call SetCameraField(CAMERA_FIELD_ROTATION, GetUnitFacing(D<i>.locked), .75)
                endif
                if (GetLocalPlayer() == Player(i)) then
                    call SetCameraField(CAMERA_FIELD_ZOFFSET, 180+(z/3), .75)
                endif
                call RemoveLocation(D<i>.loc)
            endif
            set i = i+1
        endloop
    endfunction
    
    private function TurnAct takes nothing returns nothing
        local integer i = GetPlayerId(GetTriggerPlayer())
        call SetUnitFacing(D<i>.locked,GetUnitFacing(D<i>.locked)-180)
    endfunction
    
    private function Turn takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        loop
            exitwhen i&gt;11
            call TriggerRegisterPlayerKeyEventBJ(t,Player(i),bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_DOWN)
            set i = i+1
        endloop
        call TriggerAddAction(t,function TurnAct)
    endfunction

    private function Init takes nothing returns nothing
        call Turn()
        call TimerStart(T,0.03,true,function TimerLoop)
    endfunction
    
    function SetCamTarget takes unit u, real dist,real angle, integer i returns nothing
        set D<i>.locked = u
        set D<i>.distance = dist
        set D<i>.angle = angle
    endfunction
endscope
</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>


EDIT: Only happens on very steep raised terrain.
 

Faust

You can change this now in User CP.
Reaction score
123
Periodically detect your unit's Z, and set the camera Z accordingly? Will take a few tries to get the best formula.
 

wellwish3r

wishes wells.
Reaction score
52
Periodically detect your unit's Z, and set the camera Z accordingly? Will take a few tries to get the best formula.

its doing that already, that's why it works fine with cliffs and normal elevation, but with steep elevations, the camera just shoots sky high for some reason.
 

Viikuna

No Marlo no game.
Reaction score
265
Thats because Blizzard has some sorry ass camera z height smoothing thingy that fucks everything up.

You can either try to breake it ( Toadcop posted some function for doing this ) or create some formula to compensate.

For example, this is how Oppicam camera system does it:

JASS:
call MoveLocation(Loc, newx, newy)
        set tarz = GetCameraTargetPositionZ()
        call SetCameraField(CAMERA_FIELD_ZOFFSET, GetCameraField(CAMERA_FIELD_ZOFFSET) + GetLocationZ(Loc) + Z_OFFSET + GetUnitFlyHeight(Unit[p]) - tarz, duration)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top