[JASS] [Snippet] SetCameraZ

This function lets you set camera Z exactly where you need it, the vanilla functionality of this kind is bugged because wc3 uses some sort of a height averaging algorithm so whatever height you input will change as average height around camera target changes, and this solves that issue by abusing some kind of camera mechanic.

I am posting this here not because I made it or because it's complex, but because I searched for this for a while and couldn't find it anywhere, I had to dig it out of a really old map of mine, because I forgot the exact mechanics of how it works, I was told of this snippet by ToadCop a long time ago, though I am not sure he's the one who discovered it.

JASS:
function SetCameraZ takes real z returns nothing
    set z = GetCameraField(CAMERA_FIELD_ZOFFSET) + z-GetCameraTargetPositionZ()
    call SetCameraField(CAMERA_FIELD_ZOFFSET, z, -0.01)
    call SetCameraField(CAMERA_FIELD_ZOFFSET, z, 0.01)
endfunction
 
This one does it better, as your snippet makes the camera "jerk" a little when moving. Sure it adds a little bit more overhead than just spaming this three-liner you have there, but it works way cleaner and is not dependant on a weird bug with negative time values, as this one actually reverse-engineered the camera interpolation.

Also, the system I linked allows to actually calculate the offset instead of just setting the camera, so you can use it to generate your own camera interpolation if you want that.
 
Top