How do I make an NPC or hero look like it's jumping?

From OHRRPGCE-Wiki
Jump to navigation Jump to search

Making a hero or NPC jump are done in nearly the same way. For heroes you use the hero z and set hero z commands, and for NPCs you use the npc z and set npc z commands. A hero or npc is drawn Z pixels above the point (tile) on which they are standing (or below if the Z value is negative). The rest of this article assumes NPCs, but is easily converted to heroes.

You can read the article What is the set hero Z command, and how do I correctly use it? for more information about Z values.

Bobbing[edit]

You can make an npc jump or hop to show that they are speaking by moving an npc up a few pixels and back down again. It's really simple, all you have to do is use a line of script like this:

set npc z (npc, npc z (npc) + pixels)

So take the above script and change a few things. Let's say I wanted to make NPC #2 (that's an NPC type ID, you can of course use npc references) jump up 3 pixels. I'd use this:

set npc z (2, npc z (2) + 3)

But this isn't all! That just moves the NPC up three pixels. Now we have to move him down again:

set npc z (2, npc z (2) -- 3)

Just remember to put a wait command between the two (I would recommend about 2 or 3 ticks).

So with the commands all together, the script looks like this:

set npc z (2, npc z (2) + 3)
wait (2)
set npc z (2, npc z (2) -- 3)

Jumping[edit]

But what if I want an npc to jump around rather than just blip to show that they are speaking? This is quite a different question. Firstly, if we want an npc to jump 20 pixels up and back down smoothly, we need to use a couple of for loops.

variable (npc, i)
npc := 2  # The NPC ID or reference. You can make this an argument to the script.
for (i, 1, 5) do, begin  #rise 20 pixels in 5 smalls steps
  set npc z (npc, npc z (npc) + 4)
  wait (1)
end
for (i, 1, 5) do, begin  #go back down 5 smalls steps
  set npc z (npc, npc z (npc) -- 4)
  wait (1)
end

However, this npc still ends up where it started. If you want to jump one tile forward, you need to move the npc a little in the correct direction each step by adding to the x and y components, or more simply, by using walk npc at the start of the script. You'll want to make sure that the walk command and the vertical movement take the same number of ticks. For example if the npc has move speed 4 and walks two tiles, that takes 2 tiles * 20 pixels per tile / 4 pixels per tick = 10 ticks, the same as the above pair of for loops.

See Also[edit]