• 🏆 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!

Camera System.. Smart Camera

Status
Not open for further replies.
Level 5
Joined
Jan 5, 2008
Messages
145
im making a camera system for a rpg map. and i have the camera system done right now. but however when the terrain goes up the unit goes out of sight or when the unit is in a forest the trees blocks your sight. is there a way to make the camera be smart and go up with the unit when the terrain goes up or goes up when trees are in the way? any help would be happy with me.
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
You can set the camera z by measuring the terrain height. There is a JASS function for that, it's really easy to use it:

  • CheckTerrainHeight
    • Events
    • Conditions
    • Actions
      • Set Loc = ...
      • Custom script: set udg_TerrainHeight = GetLocationZ(udg_Loc)
So you need a point variable named "Loc" and a real variable named "TerrainHeight" (you can name them whatever you want, but be sure to change that in the custom script line also).

After that you have the terrain height stored in the TerrainHeight variable and you can change camera z to whatever you want.

That tree part looks a bit complicated to me...
 
Level 5
Joined
Jan 5, 2008
Messages
145
ok it works but what do i set for LOC? i put ... and w.e crashed lol this is what i put

Code:
function Trig_Updating_Camera_Actions takes nothing returns nothing
    set udg_Loc = ...
    set udg_TerrainHeight = GetLocationZ(udg_Loc)
    call SetCameraFieldForPlayer( Player(0), CAMERA_FIELD_TARGET_DISTANCE, 750.00, 0.10 )
    call SetCameraFieldForPlayer( Player(0), CAMERA_FIELD_ANGLE_OF_ATTACK, 345.00, 0.10 )
    call SetCameraFieldForPlayer( Player(0), CAMERA_FIELD_ZOFFSET, ( 100.00 + ( GetUnitFlyHeight(udg_CurrentUnit) + udg_TerrainHeight ) ), 0.10 )
    call SetCameraFieldForPlayer( Player(0), CAMERA_FIELD_ROTATION, GetUnitFacing(udg_CurrentUnit), 0.10 )
endfunction
also for camera z offset should i add terrain height or Loc to determine where the camera should be?
 
Level 19
Joined
Oct 29, 2007
Messages
1,184
Uhm.. Been struggeling with this too for a long time. Luckily I was able to figure this out by looking at a map. When I looked into the map I found this code:

JASS:
function SetCameraZ takes player whichPlayer, real z returns nothing
    if ( GetLocalPlayer() == whichPlayer ) then
    set z = GetCameraField(CAMERA_FIELD_ZOFFSET)+z-GetCameraTargetPositionZ()
    call SetCameraField(CAMERA_FIELD_ZOFFSET,z,- 0.01)
    call SetCameraField(CAMERA_FIELD_ZOFFSET,z,0.01)
    endif
endfunction
'

Put it somewhere.

Then do these things in your camera trigger:

  • Actions
    • Set tmp_loc = (Position of YOUR UNIT
    • Custom script: set udg_view_height=GetLocationZ(udg_tmp_loc)
    • Custom script: call SetCameraZ( ConvertedPlayer(udg_tmp_integer), udg_view_height)
Adjust it the way you want, and the height of the camera should increase properly with the heigh of the unit. ; )

What Silvenon suggested would also work, but if you look close the height still won't change properly that way.
 
Level 5
Joined
Jan 5, 2008
Messages
145
Thanks Megafyr Do i have to make any variables? for it or is it set in the code. cause im still learning Jass and that was a bit confusing. Oh and btw

I found a leak it my camera code and i look in the leaks section and couldn't find how to stop a camera leak so ill just post all my codes and since i suck at finding leaks :( maybe someone can help me some leaks

JASS:
function Trig_Initialization_Camera_Func001C takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetTriggerUnit()) == Player(0) ) ) then
        return false
    endif
    return true
endfunction
function Trig_Initialization_Camera_Actions takes nothing returns nothing
    if ( Trig_Initialization_Camera_Func001C() )
 then
        set udg_CurrentUnit = GetTriggerUnit()
        call SetCameraTargetControllerNoZForPlayer( Player(0), udg_CurrentUnit, 0, 0, false )
        call EnableTrigger( gg_trg_Updating_Camera )
    else
        call DoNothing(  )
    endif
endfunction
//===========================================================================
function InitTrig_Initialization_Camera takes nothing returns nothing
    set gg_trg_Initialization_Camera = CreateTrigger(  )
    call TriggerRegisterPlayerSelectionEventBJ( gg_trg_Initialization_Camera, Player(0), true )
    call TriggerAddAction( gg_trg_Initialization_Camera, function Trig_Initialization_Camera_Actions )
endfunction

JASS:
function Trig_Go_Back_To_Reg_Camera_Actions takes nothing returns nothing
    set udg_CurrentUnit = null
    set udg_Loc = null
    call ResetToGameCameraForPlayer( Player(0), 0.10 )
    call DisableTrigger( gg_trg_Updating_Camera )
endfunction

//===========================================================================
function InitTrig_Go_Back_To_Reg_Camera takes nothing returns nothing
    set gg_trg_Go_Back_To_Reg_Camera = CreateTrigger(  )
    call TriggerRegisterPlayerSelectionEventBJ( gg_trg_Go_Back_To_Reg_Camera, Player(0), false )
    call TriggerAddAction( gg_trg_Go_Back_To_Reg_Camera, function Trig_Go_Back_To_Reg_Camera_Actions )
endfunction

JASS:
function Trig_Updating_Camera_Actions takes nothing returns nothing
    set udg_Loc = GetUnitLoc(udg_CurrentUnit) 
    set udg_TerrainHeight = GetLocationZ(udg_Loc)
    call SetCameraFieldForPlayer( Player(0), CAMERA_FIELD_TARGET_DISTANCE, 750.00, 0.10 )
    call SetCameraFieldForPlayer( Player(0), CAMERA_FIELD_ANGLE_OF_ATTACK, 345.00, 0.10 )
    call SetCameraFieldForPlayer( Player(0), CAMERA_FIELD_ZOFFSET, ( 100.00 + ( GetUnitFlyHeight(udg_CurrentUnit) + ( udg_TerrainHeight / 2.00 ) ) ), 0.10 )
    call SetCameraFieldForPlayer( Player(0), CAMERA_FIELD_ROTATION, GetUnitFacing(udg_CurrentUnit), 0.10 )
endfunction

//===========================================================================
function InitTrig_Updating_Camera takes nothing returns nothing
    set gg_trg_Updating_Camera = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Updating_Camera, 0.01 )
    call TriggerAddAction( gg_trg_Updating_Camera, function Trig_Updating_Camera_Actions )
endfunction

idk where to put megafyrs helpful code >.< lol . ugh megafyr you crashed my w.e >.< your code has alot of compile errors
 
Level 19
Joined
Oct 29, 2007
Messages
1,184
I doesn't matter where you put it I think. I have it in the map header.


Then Inside your camera trigger do these things (WARNING I AM JASS NOOB):

JASS:
local location l
local integer i
set l = //Position of your unit
set i=GetLocationZ(l)
call SetCameraZ( ConvertedPlayer(), i)
call RemoveLocation(l)

Think that should be working.

Btw, you don't need
JASS:
call DoNothing(  )
It calls a function that ... Does nothing. :)
 
Level 5
Joined
Jan 5, 2008
Messages
145
i did eaxactly as you said and i got 7 compile errors

set udg_CurrentUnit = GetTriggerUnit() Expected "EndIf"
local location l Expected "EndIf"
local integer i
set l = udg_CurrentUnit Expected Variable Name
set i=GetLocationZ(l) Expected Variable Name
call SetCameraZ( ConvertedPlayer(), i) Invaild Number Of Arguments
call RemoveLocation(l) Expected A Name

Then for Some Reason

call TriggerAddAction( gg_trg_Updating_Camera, function Trig_Updating_Camera_Actions ) Expected A Function Name Wtf
 
Status
Not open for further replies.
Top