• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] First Person Camera Problem

Status
Not open for further replies.
Level 3
Joined
May 19, 2010
Messages
34
Hey guys,

So I've been trying to make a good first person camera for a few days and I'm having trouble.

Basically I can make the camera follow the unit when walking around on flat ground and it follows the unit when walking up HILLS (i.e. terrain that has had "Apply Height" performed on it). But when I go up CLIFFS to a higher cliff level it starts getting more and more offset.

EDIT : I just checked the numbers again for hills and they don't work exactly right either (although they aren't as bad as the cliffs)

For example, I have a map with original cliff level 0 and I attach my camera to the unit so that it's at the right height, as if looking out the unit's eyes. When I walk up one cliff level, the unit's Z position goes from -256 to -128, an increase of 128. So I would expect the camera's Z offset to increase by 128 as well. However, when I check the camera's Z source it increases by around 190 :eekani:.

By the time I've gone up 3-4 cliff levels the camera is a few hundred units too high :angry:.

I've been researching it for ages and it seems like you have to adjust the way you change the camera's Z offset depending on what cliff level you're standing on, but I just can't seem to figure out how.

Here's the system I use, I've seen it in alot of threads :

  • Set CameraZ = (Position of Camera 0001 <gen>)
  • Custom script: set udg_UnitZ = GetLocationZ(udg_CameraZ)
  • Camera - Set Player 1 (Red)'s camera Height Offset to (UnitZ + 300.00) over 0.00 seconds
  • Custom script: call RemoveLocation(udg_CameraZ)

I'll attach the map too (ignore the primitive movement system). I constantly print out the unit height and the camera Z height in chat, which is when I noticed that they were changing differently.

Any help would be appreciated, thanks!
 

Attachments

  • Test1.w3x
    36.1 KB · Views: 44
Last edited:
This is because the camera height gets interpolated over the terrain height to prevent the default camera from bumping up/down on every cliff or hill.

To counter it, you can use this lib:
http://www.hiveworkshop.com/forums/graveyard-418/getcamoffset-131434/

It basicly returns the offset you need to apply to the camera to correct the camera interpolation.
 
Level 3
Joined
May 19, 2010
Messages
34
Yeah I figured there was something else going on haha.

Thanks for the lib Zwiebelchen but unfortunately I have next to no JASS knowledge :(. Been looking up how to even use libraries in your own map xD. Don't even know how to import or use the GetCamOffset function.

Looking at it though, how would the value that GetCamOffset(x,y) returns be different to "Source Z of Current Camera"?

And how would I use it to know what to set the height to?

Sorry for the ignorance, I'm JASS nublet
 
You can evaluate the cliff level and add/substract the correct value to fix the height again.

Note: I think when you make walkable water, the cliff difference differs I think. (sth like 76 instead of 128)
But if you only make normal cliffs it should be always same.

And try this for your hills:

set udg_UnitZ = GetLocationZ(udg_CameraZ)
-->
set udg_UnitZ = 0.66 * GetLocationZ(udg_CameraZ)
 
Level 3
Joined
May 19, 2010
Messages
34
Thanks IcemanBo, that gave me an idea about finding the cliff level and adding an extra change depending on what level it was. This is the ugly function that I ended up with haha

  • Camera - Set Player 1 (Red)'s camera Height Offset to (UnitZ + (300.00 - (((UnitZ + 256.00) / 128.00) x 90.00))) over 0.00 seconds
I set up a long ramp up like 6 levels and it worked! (sort of)...by changing the last value around I could get the camera height fairly constant when walking up multiple cliff levels.

The problem now is the camera still gets interpolated, which means two things :

1. At the top of the cliff there was a sheer drop down (cos I was just stacking cliffs on top of each other) and when i approached that edge the camera went down before I was close and went through the ground (in anticipation of me walking over the edge and descending)

2. That messy trigger I posted kind of works for walking up ramps, but now it doesn't really work with hills, I end up not rising far enough and just clipping through the ground.

I can't figure out the maths to directly set the camera according to the unit's Z co-ordinate and ignore interpolation (i.e. I just want to keep the camera's Z offset 75 units higher than unit's Z axis co-ordinate at all times) :cry:.

I assume even if I didn't "lock" the camera to the unit and just controlled it manually the stupid camera would still interpolate


EDIT : Btw IcemanBo I used your recommendation for the hills, multiplying by 0.66 and it seemed to work, but then I had to change the function in order to get the cliffs to work, which just messed it all up again ><.
 
Level 3
Joined
May 19, 2010
Messages
34
Hehe just ignore my formula, it isn't a long-term solution anyway :xxd:

You could use reals before to evaluate Z for unit and Z for cliffs.

Sorry I don't quite understand this, "before" what? The camera changes before the unit even goes over the cliff, so I don't know how I'd find out about a specific point on the cliff or info about the slope's Z numbers.
 
I see, yes that automatically change sucks if its not wanted. Best would maybe to avoid blizzard cliffs at all and only try to work with hills.

And I meant you could evaluate reals before you do the action "Change Cam Height", only to get a better overview. (so you know what exactly is your formula for unitZ, and what is for cliff-fix)
 
Level 3
Joined
May 19, 2010
Messages
34
Ohh I gotcha.

Yeah it's very annoying haha. I'm thinking some involved JASS and maths is going to be the answer, but I'm not too sure. Guess I'll keep trying, see if I can get any further. Cheers IcemanBo!

In the meantime, if anyone else has any ideas I'm open to them!
 
Level 3
Joined
May 19, 2010
Messages
34
I finally got it working!!

With help from the awesome Anitarf I figured out how to make it work. First you have to use the GetCamOffset library Zwiebelchen linked. Then it's a fairly simple calculation to set it at the right height and keep it there :

  • Set CameraPoint = (Position of Camera 0001 <gen>)
  • Set CameraX = (X of CameraPoint)
  • Set CameraY = (Y of CameraPoint)
  • Custom script: set udg_CameraZ = GetLocationZ(udg_CameraPoint)
  • Custom script: set udg_UnitZ = GetCamOffset(udg_CameraX, udg_CameraY)
  • Camera - Set Player 1 (Red)'s camera Height Offset to ((100.00 + CameraZ) - UnitZ) over 0.00 seconds
  • Custom script: call RemoveLocation(udg_CameraPoint)
NOTE!!!!
The Camera 0001 you see in the first line isn't a camera, it's a unit based on a peasant called "Camera". It was a stupid choice, I should have called the unit "CameraDummy" or something, but I wasn't thinking as this was just a test map

Also, I used 100 here when setting height offset, but you might have to play around with it in your individual maps as it could vary. But yeah, thanks again to Anitarf and to you guys for your posts.

SOLVED! :D.

P.S. I don't know how to change the thread title from "TRIGGER" to "Solved" :p....
 
Pro-tip:
If you get the vertical distance between the "camera eye position" (in addition to the target position) and the ground, you can tilt the camera a little to make it "look up" a cliff you are approaching.

This makes walking up/down ramps a lot easier, especially if the cliff is steep.
It will also avoid clipping when walking down a ramp.
 
Level 3
Joined
May 19, 2010
Messages
34
Pro-tip:
If you get the vertical distance between the "camera eye position" (in addition to the target position) and the ground, you can tilt the camera a little to make it "look up" a cliff you are approaching.

This makes walking up/down ramps a lot easier, especially if the cliff is steep.
It will also avoid clipping when walking down a ramp.

Thanks Zwiebelchen, it just so happens that yesterday I realised that I'll need to do that for one of my features to work! xD. So your post had great timing :grin:.

Cheers
 
Status
Not open for further replies.
Top