HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Camera Height Offset

03-13-2005, 10:49 AM#1
Hyarion
I need help. I've created a lovely third person camera system. I even managed, after some work, to make it so that you can use the left and right arrow keys to rotate it around your hero, or hit the ESC key to lock it to your hero's facing angle. This is all fine. My problem is that the camera doesn't follow my hero up hills. I've managed to make it so that the players can alter the height of the camera with the up and down arrow keys, but this seems...inelegant. Can anyone think of a way to make the camera autoset it's height offset to correspond to the terrain? I tried making a series of tiny regions that follow the heroes, and setting it to height of region + 140, but that didn't work... Can anyone help me with this, please and thankyou?
03-13-2005, 02:44 PM#2
Hyarion
Sorry to bump this but I really need the help...
03-13-2005, 09:35 PM#3
Guest
Lord Vexorian discovered a new unannounced native function in patch 1.18:
GetLocationZ(). You can use that to get the height of your unit position and just raise the height of camera automatically. I had another system made, but it's much more simple now with this new function.

Salutions®
03-14-2005, 02:38 AM#4
Guest
Wow... I had the EXACT same problem and it worked for me, even though I know nothing about JASS.
03-14-2005, 08:07 AM#5
Hyarion
EXCELLENT! I was just planning, if no-one had answered this, to ask in the JASS forum if such a function existed! WONDERFUL!
03-14-2005, 11:46 AM#6
johnfn
There is also
Code:
 GetTerrainCliffLevelBJ takes location where returns integer

which returns cliff levels, which might be helpful since that get Z function is rumored to ONLY get terrain deformations and not how high the cliffs are...this is to be verified though.
03-14-2005, 01:02 PM#7
Hyarion
Right, one last question:
I have a unit array: PlayerHero[1-10], and am planning on making a real arry CameraZ[1-10], obviously one for each human player. My question is this: Can someone give me the JASS script nessecary to set CameraZ[x] to the height of the terrain under PlayerHero[x], using the GetLocationZ() function? Sorry to be a bother, but I don't know anything about JASS. I was planning a trigger like:

Event:
Every 0.05 Seconds of Game Time
Conditions:
Actions:
Player- Pick every playe in all players controlled by a (user) player and do (Set (CameraZ[Player Number Of (Picked Player)] to {Custom Script Here}

But I don't know if that'll work. All I want is to set the CameraZ for a picked player to the height of the terrain under the PlayerHero for that player. NOT using the terrain cliff heights, using the GetLocationZ() function.

Please help...
03-14-2005, 11:38 PM#8
Guest
Okay, this is how you would do it. You will need two variables: Real Array CameraZ and Unit Array Player Hero.

function Trig_Set_Camera_Func001002 takes nothing returns nothing
set udg_CameraZ[GetConvertedPlayerId(GetTriggerPlayer())] = GetLocationZ(GetUnitLoc(udg_PlayerHero[GetTriggerPlayer()]))
endfunction

function Trig_Set_Camera_Actions takes nothing returns nothing
call ForForce( GetPlayersByMapControl(MAP_CONTROL_USER), function Trig_Set_Camera_Func001002 )
endfunction

//===========================================================================
function InitTrig_Set_Camera takes nothing returns nothing
set gg_trg_Set_Camera = CreateTrigger( )
call TriggerRegisterTimerEventPeriodic( gg_trg_Set_Camera, 0.05 )
call TriggerAddAction( gg_trg_Set_Camera, function Trig_Set_Camera_Actions )
endfunction

Just paste the whole thing into a trigger. Hopefully it will work.
03-15-2005, 10:02 AM#9
Hyarion
I don't know whether your trigger would've worked or not, in the end I simply made the triggers in the GUI using "Y Of Point" converted them to custom text and changed Y to Z, but I now have a new problem:
The Camera Height Offset seems to change a bit when the height of the terrain under the unit does, but it doesn't change consistantly, which is why it doesn't follow it up hills automatically. The fact that it DOES change on its own, albeit only slightly, means that I cannot simply set the Camera Height Offset to (the Z of the unit's position + (the normal Camera Height Offset when the unit is on terrain of Z=0)), as it winds up far above the unit. The only trigger I have found that works so far is a monster 200-odd line IF THEN ELSE thing, going something like:

Events:
Every 0.05 Seconds of Game Time
Conditions:
Actions:
IF Z of (Position of (PlayerHero[Player Number Of (Picked Player)] is greater than (140) THEN Set (Camera Height Offset) for (Picked Player) to (160)
ELSE
IF Z of (Position of (PlayerHero[Player Number Of (Picked Player)] is greater than (160) THEN Set (Camera Height Offset) for (Picked Player) to (180)
ELSE
IF Z of (Position of (PlayerHero[Player Number Of (Picked Player)] is greater than (180) THEN Set (Camera Height Offset) for (Picked Player) to (200)
-
-
-
-
-
-
-
All the way down to:
IF Z of (Position of (PlayerHero[Player Number Of (Picked Player)] is greater than (1000) THEN Set (Camera Height Offset) for (Picked Player) to (1000)
ELSE
Set (Camera Height Offset) for (Picked Player) to (Camera Z Of ThirdPersonViewCamera)

The problem was that when I converted to custom text and tried to enable the trigger, it had dozens of errors. Note that this was BEFORE I tried editing the custom text at all. It happened as soon as I tried to enable the trigger. A trigger practically identical to this but smaller, DID work. So far, I seem to have two options.
One: Change the trigger shown above so that the numbers are every fifty, rather than every twenty, thus reducing the size and hopefully allowing it to work properly.
Two: Make a trigger to display the Z of the terrain under the unit and the Height Offset of the camera, then take notes on the two as I move, and plot a graph of them to find the equation for their relationship.
03-15-2005, 11:47 AM#10
johnfn
/cry...


You are going to hate me for this. Cant you just do

Set (Camera Height Offset) for (Picked Player) to (Z of (Position of (PlayerHero[Player Number Of (Picked Player)] + 20)

setting it to the Z, rather then comparing Z's and then setting it?!
03-15-2005, 03:27 PM#11
Hyarion
I tried that first of all. That was my first idea, as, as you said, it was insanely simple. Because of the fact that I know how skilled you are, I tried it again, in case some mistake had been made. This time it worked. And I know why. The first time I tried it, when I converted to custom text, I had missed one of the "Y" references, and not changed it to "Z". I feel like punching myself... :-P