Is there a way to get Z coordinat of a unit/region/point?

Discussion in 'JASS Zone' started by Insanewarlock, Aug 27, 2014.

  1. Insanewarlock

    Insanewarlock Active Member

    Ratings:
    +2 / 0 / -0
    I need the camera height offset to change when player walks up a mountain my third person map. How do I do set my HeightVar to the Z coordinate of the unit/hero?
     
  2. Accname

    Accname 2D-Graphics enthusiast

    Ratings:
    +1,551 / 4 / -4
    There is a way with jass, but not with GUI.
    You first get the location of the unit / whatever. Then you can get the Z-coordinate of the location with getLocationZ (or something like that, not sure about the exact syntax).
     
    • Like Like x 1
  3. Insanewarlock

    Insanewarlock Active Member

    Ratings:
    +2 / 0 / -0
    Do I need a JASS trigger or custom script is enough? What is this?
    Code:
    call SetCameraZ(GetEnumPlayer(), udg_playerCameraZ[GetConvertedPlayerId(GetEnumPlayer())]+128)
    I fount it on the following map:
    http://www.hiveworkshop.com/forums/map-development-202/third-person-shooter-test-map-127704/

    I don't know JASS at all so that's why I'm asking the question. I know few programing languages but JASS is kinda confusing. Can you help?

    And also somebody on this forum had made the camera height offset dependent on terrain height but I cant understand it at all.... I see your post there :D
     
  4. Accname

    Accname 2D-Graphics enthusiast

    Ratings:
    +1,551 / 4 / -4
    You dont have to make the whole trigger in jass, a single line of custom code is enough.
    The line should look somewhat like this:
    Code:
    set udg_SomeReal = GetLocationX(udg_SomePoint)
    where SomeReal is some kind of real variable and SomePoint is some kind of point variable.
     
    • Like Like x 1
  5. Insanewarlock

    Insanewarlock Active Member

    Ratings:
    +2 / 0 / -0
    Oh it didn't work.... Errors popped up. I created thre variables: Unit (var type unit), Unit_Point (var type point), and Unit_Height (var type real). I attached my hero to Unit in initialization than created 3 actions in periodic event:
    Code:
    Set Unit_Point = (Position of Unit)
    Custom script: set udg_Unit_Height = GetLocationX(udg_Unit_Point)
    Camera - Set Player 1 (Red)'s camera Height Offset to (Unit_Height+130.00) over 0.1 seconds.
    Whad did I do wrongly?
     
  6. Accname

    Accname 2D-Graphics enthusiast

    Ratings:
    +1,551 / 4 / -4
    Works for me:
    Code:
    Trigger
      Events
        Player - Player 1 (Red) selects a unit
      Conditions
      Actions
        Set Point = (Position of (Triggering unit))
        Custom script:  set udg_Real = GetLocationZ(udg_Point)
        Game - Display to (All players) the text: (String(Real))
    
     
    • Informative Informative x 1
  7. Insanewarlock

    Insanewarlock Active Member

    Ratings:
    +2 / 0 / -0
    Thank you so much! Finally I've made but with a small issue as always.... :D The script looks like this:
    (Only the height regulation part)
    Trigger:
    • Events
      • Time - Every 0.10 seconds of game time

    Trigger:
    • Actions
      • set Unit_Point = (Position of Unit)
      • Custom script: set udg_Unit_Height = GetLocationZ(udg_Unit_Point)
      • Camera - Set Player 1 (Red)'s camera Height Offset to (180.00 + (0.02 x Unit_Height)) over 0.10 seconds


    It took a long time to figure out this linear function: 180 + (0.02 x Unit_Height) and it's very good when the terrain is flat and wide enough, but if the area is small sized the game seems to be regulating height without my request, looks like auto height offset correction. How do I turn that off? Don't think that Z coordinate (Unit_Height) is not changing when that happens, it does, I've checked, there is some kind of auto regulation, I've spotted it even when this height offset regulation (script shown above) was turned off and offset was constant.

    And the other (final) issue I have, which is a wholly different question (should I make a different thread about it? First help me formulate the question or give me hints please if you don't know how to solve it), how should my camera avoid other objects like mountains and trees? The problem is not that big because besides camera rotating according to unit's facing angle, I created camera rotation with arrow control <- ^ v -> and you can simply avoid moments when camera crushes into something, but you still see these moments when it happens before you try to rotate the camera and it looks pretty ugly. Do you have any ideas? "Ultimate Third Person Camera" claims to have solved it, how did he do that?

    Again, I'm really grateful for your help!
     
    Last edited: Aug 28, 2014
  8. Accname

    Accname 2D-Graphics enthusiast

    Ratings:
    +1,551 / 4 / -4
    I think you are talking about the cliffs. Cliffs in wc3 will make the camera go higher automatically. I dont know if there is much you can do except take the cliff level of the unit into consideration, but that will probably still not be accurate all the time.
     
  9. Insanewarlock

    Insanewarlock Active Member

    Ratings:
    +2 / 0 / -0
    Yes, yes!
    I don't seem to understand you, what is the cliff level of the unit?

    I could mark every region containing cliffs and set different height offset there for camera but it's not really that bad I think. I'll just make a map with less cliffs =D But what about the other problem? When camera is looking underground? I partially solved the problem by changing distance to target and angle of attack so it's happening less often. Maybe it would be better to leave the script simple. Check it out how would you rate it out of 10? :D Don't forget to rotate camera with arrows.

    https://drive.google.com/file/d/0B9pUVpJO3AdqV2g1QUthZlJ1VWM/edit?usp=sharing
     
  10. Accname

    Accname 2D-Graphics enthusiast

    Ratings:
    +1,551 / 4 / -4
    You can get the cliff level (height of cliff) at a certain location. For example at the location of the unit.
    Each cliff level has a height of 128. So if you take the cliff level at the units location, multiply it with 128 and subtract that value from your cameras Z value you might get closer to what you want.
    But the problem is that the units location is not the location of the camera. It would be more accurate if you can find the location of the camera and use the cliff level at that point for your calculation.

    In pseudo-code this might look somewhat like this:
    Code:
    unitLoc = position of unit
    camLoc = unitLoc offset by CAM_DISTANCE towards (CAM_ANGLE - 180) degres
    cliffLvl = get cliff level at camLoc
    unitZ = get location Z for unitLoc
    camZ = CAM_HEIGHT_FIX + unitZ - (cliffLvl * 128)
    
    Experiment with the values, of course, but this might help you a little bit.
     

Share This Page