What is the set hero Z command, and how do I correctly use it?

From OHRRPGCE-Wiki
Jump to: navigation, search

set hero Z and set NPC Z are interesting plotscripting commands. They are like setting hero/NPC Y position with set hero position/set NPC position, but are't. Essentially, they make your hero or NPC hover.

If you know anything about Cartesian planes (X/Y grids), you'll know that any point on a 2-dimensional grid (or, say, map) can be represented by a pair of numbers (the (X,Y) coordinates). Similarly, a 3-dimensional grid uses 3 numbers (X, Y and Z), with Z being the "height".

Now, since the OHR is a 2-D engine, Z is used to simulate "height off the map". This is done by subtracting the Z value from the Y when it's drawn. So, if a sprite is at the pixel (100,100), and has a Z of 20, then it is drawn at the pixel (100,80).

So, back to set hero Z. Let's say you have a hero named Sven. Normally, when Sven walks around, he bumps into walls and what not as you would expect: he can't pass through walls or NPCs at all.

Now, let's say that you use a bit of plotscripting magic on him, and use this command:

set hero Z (me, 10)

What that does is cause Sven to look like he's 10 pixels higher than he was before. But, if you move around, you'll see that he's not really 10 pixels higher: the walls and NPCs around him still block him and prevent him from moving.

Now, let's send Sven even higher:

set hero Z (me, 40)

Now, Sven looks like he's a whole two tiles higher. But, he still acts like he was on the ground.

What can you use this mystical command for, you ask? Primarily, it's used for jumping. Lets say that you have a cutscene where Sven jumps over a pit or something, it's easier to use set hero Z than actually changing his Y:

script, jumping cutscene, begin
  show text box (1) #I must jump over this pit!
  wait for text box
  wait(10)

  suspend hero walls
  #Heros move at 4 pixels per frame. Thus, it takes 5 frames to move one tile:
  walk hero (me, left, 1) #move 1 tile left
  set hero Z (me, 2)     #Frame 1
  wait(1)
  set hero Z (me, 4)     #Frame 2
  wait(1)
  set hero Z (me, 6)     #Frame 3
  wait(1)
  set hero Z (me, 4)     #Frame 4
  wait(1)
  set hero Z (me, 2)     #Frame 5
  wait(1)
  resume hero walls

  wait(10) 
  show text box(2) #all done!
end

Foot offset[edit]

Maps also have a "foot offset" off the ground, which is added to Y position for all the NPCs and heroes. Foot-offset isn't Z, it's just the offset from the tile grid at which walkabouts are drawn. If you want to modify this instead, use set foot offset.

Note that the Z value for heroes/NPCs is always 0 by default regardless of the footoffset. The only time that the Z changes is if you change it with a script, or if you board a vehicle which rises into the air.

See Also[edit]