I want to imitate the movement of the "Death" boss enemy in Wonderboy in Monster Land.

At first, I thought it just moves with a sine wave, but it's not. The up and down movement is erratic.

I thought it changes its facing direction at the player's x position, but as you see in the video, it did not change direction when player jumped.

And if the player sits under the boss, the boss just moves up and down and changes direction irregularly.

So far I've tried to imitate its movement with this:

transform.position = pos + transform.up * Mathf.Sin(Time.time * frequency) * amplitude;

I used sine, but it's quite different from movement of the boss. How can I change the behaviour in my game to be more like this boss's movement?


I never played that game myself.

It looks like it has a state machine.
If the horizontal offset between player and boss is high enough, it moves in a horizontal + sinus movement.
If it is near the player, it moves up to evade the player, abandoning the sinus.
After it avoided the player, it keeps doing a slightly larger sinus above the player, and sometimes collides with the player.

I think the erratic moves are the state switches, going from horizontal + sin, to evade, to stationary + sin to horizontal + sin.
I don't see an attack pattern, it's more of an follow and don't touch movement.
I believe the difficulty from this boss stems from the fact that the player is mele, and still needs to do damage without accidentally hitting the ghost.

Thus to replicate the movement, you would need to replicate these four states and their respective movement pattern.

| improve this answer | |
  • \$\begingroup\$ it's little bit hard to find a pattern from it but i'll try to add FSM for it. i just hard coded it. thanks again! \$\endgroup\$ – Hree Aug 21 '19 at 5:01

One tool I find very useful for creating movement patterns is the timeline asset. The advantage of using timelines for this is that you can describe the movement patterns using curves in a visual editor instead of describing them as mathematical functions or algorithms. This is usually far more intuitive and designer-friendly.

You can even do it in the Unity editor. When you want the boss to be in the upper left corner at second 2 and in the center of the screen at second 3, then you:

  1. enable recording for that object in the timeline editor
  2. move the timeline to second 2
  3. move the object to the first position using the usual editor controls,
  4. move the timeline to second 3,
  5. move the object to the second position.

The timeline editor will now have generated curves for the x and y coordinate which smoothly interpolate between these positions. You can then tweak these movement curves by adding additional points in between or moving points around.

For example, my entry "Slacking At Work Simulator" for the Useless Simulation Game Jam two weeks ago on itch.io makes a lot of use of timelines. The most visible example is the movement of the antagonist. His x position, y position and rotation is controlled completely by one 5 minute long timeline.

However, timelines have one crucial disadvantage: They can not react to what happens in the game.

Going back to the boss monster from the youtube video in the question: It appears to me as if the y-position of the opponent follows a fixed pattern while the x-position reacts to the player position. So you could combine a timeline which controls transform.y with a script which controls transform.x by always moving towards the current position of the player.

| improve this answer | |
  • \$\begingroup\$ I dont think the timeline editor is really of use for this problem, as the enemys movement clearly are dependant ont he players position. And not just the x-pos but also the y-pos, as the ghost in the video only gets much higher to somewhat avoid the player sometimes and lower to hit the player, not just randomly up and down movements. \$\endgroup\$ – PSquall Aug 19 '19 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.