HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

3rd Person camera

09-15-2007, 03:30 AM#1
Immoralis
This is a trigger that is supposed to cause the players to have a 3rd person view for his/her respective hero in question. However, it fails to do that. Currently on single player, the camera always faces 0 degrees regardkess of my Hero's rotation. When I ping the position of target, on single player, it pings the person of the Hero that I control, however, it also pings the middle a number of times(probably 11). Also, when I made it display the rotations, it displays my marines rotation, along with 11 0's. TP_Camera_Group is initialized in the beginning to include all players controlled by a user. Any suggestions?

Collapse JASS:
function Trig_Third_Person_Camera_Actions takes nothing returns nothing
    local unit target = udg_Players_Marine[GetConvertedPlayerId(GetEnumPlayer())]
    local player owner = GetEnumPlayer()
    local location origin = GetUnitLoc(target)
    local real CameraMod
    
    if ( (GetTerrainCliffLevelBJ(PolarProjectionBJ(origin, 600.00, GetUnitFacing(target))) >= (GetTerrainCliffLevelBJ(origin)+3)) or (GetTerrainCliffLevelBJ(PolarProjectionBJ(origin, 600.00, GetUnitFacing(target)+90)) >= (GetTerrainCliffLevelBJ(origin)+3)) or (GetTerrainCliffLevelBJ(PolarProjectionBJ(origin, 600.00, GetUnitFacing(target)-90)) >= (GetTerrainCliffLevelBJ(origin)+3))) then
        set CameraMod = -4
    else
        if( (GetTerrainCliffLevelBJ(PolarProjectionBJ(origin, 600.00, GetUnitFacing(target))) >= (GetTerrainCliffLevelBJ(origin)+2)) or (GetTerrainCliffLevelBJ(PolarProjectionBJ(origin, 600.00, GetUnitFacing(target)+90)) >= (GetTerrainCliffLevelBJ(origin)+2)) or (GetTerrainCliffLevelBJ(PolarProjectionBJ(origin, 600.00, GetUnitFacing(target)-90)) >= (GetTerrainCliffLevelBJ(origin)+2))) then
            set CameraMod = -1.50
        else
            if ( (GetTerrainCliffLevelBJ(PolarProjectionBJ(origin, 600.00, GetUnitFacing(target))) >= (GetTerrainCliffLevelBJ(origin)+1)) or (GetTerrainCliffLevelBJ(PolarProjectionBJ(origin, 600.00, GetUnitFacing(target)+90)) >= (GetTerrainCliffLevelBJ(origin)+1)) or (GetTerrainCliffLevelBJ(PolarProjectionBJ(origin, 600.00, GetUnitFacing(target)-90)) >= (GetTerrainCliffLevelBJ(origin)+1))) then
                set CameraMod = 0.00
            else
                set CameraMod = 1.00
            endif
        endif
    endif
    call PingMinimapLocForForceEx( GetPlayersAll(), GetUnitLoc(target), 1, bj_MINIMAPPINGSTYLE_SIMPLE, 100, 100, 100 )
    call DisplayTextToForce(GetPlayersAll(),R2S(GetUnitFacing(target)))
    call SetCameraTargetControllerNoZForPlayer( owner, target, 0.00, 0, false )
    call SetCameraFieldForPlayer( Player(0), CAMERA_FIELD_ROTATION, GetUnitFacing(target), 0.33 )
    call SetCameraFieldForPlayer( Player(0), CAMERA_FIELD_TARGET_DISTANCE, 475.00, 0.33 )
    call SetCameraFieldForPlayer( Player(0), CAMERA_FIELD_ANGLE_OF_ATTACK, 340.00, 0.33 )
    call SetCameraFieldForPlayer( Player(0), CAMERA_FIELD_ZOFFSET, ( ( I2R(GetTerrainCliffLevelBJ(origin)) + CameraMod ) * 43.00 )-14, 0.66 )
    
    call RemoveLocation(origin)
    set origin = null
    set target = null
    set owner = null
endfunction

function Third_Person_Camera_Helper takes nothing returns nothing
    call ForForce( udg_TPCamera_Group, function Trig_Third_Person_Camera_Actions )
endfunction
//===========================================================================
function InitTrig_Third_Person_Camera takes nothing returns nothing
    set gg_trg_Third_Person_Camera = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Third_Person_Camera, 0.25 )
    call TriggerAddAction( gg_trg_Third_Person_Camera, function Third_Person_Camera_Helper )
endfunction
09-17-2007, 04:42 AM#2
Morlark
For the pings and displaying the rotations, I think what's happening is that since you're doing it for all players, it's attempting to ping the locations of all players' heroes to all players. I presume you were testing this with only one player, so the players that were not present had no hero, and it pinged the centre of the map instead.

As for the camera oddness, I actually had exactly the same problem in my own map recently. Through lots of testing, I found that the SetCameraFieldForPlayer() function behaves somewhat oddly. Basically, it doesn't work at all if you try to use a function or a variable as the third parameter. The only way it'll work is if you supply a real number directly into the function. Based on comments in the blizzard.j file, I can only assume that this is a (poorly documented) feature.

To get this to work, you have to use the SetCameraField() function instead. Note that this will apply the camera change to the local player, so you'll have to do something along the lines of:

Collapse JASS:
    if (GetLocalPlayer() == owner) then
        call SetCameraField( CAMERA_FIELD_ROTATION, youranglehere, 0.33 ) 
    endif