Solarus Forum

Solarus => Development => Topic started by: Max on December 22, 2018, 08:02:41 pm

Title: Weird Stairs Issue
Post by: Max on December 22, 2018, 08:02:41 pm
Hey guys, just downloaded 1.6 and I've got a weird issue.

It seems like platform stairs won't push the hero up a level unless you hit them EXACTLY straight on. For a staircase only 16px wide, this is no problem, but if a staircase is wider, the player might be moving up the stairs straddling two tiles- in this situation it seems like the entities act like a wall.

I've attached a gif that hopefully shows that's going on better, and a couple screenshots of the way the tiles are laid out.

Hopefully I've just been putting stairs together incorrectly this whole time and it's not the first post-release 1.6 bug?

(https://i.imgur.com/XWlOwvf.gif)
Title: Re: Weird Stairs Issue
Post by: Christopho on December 22, 2018, 11:31:31 pm
I think this problem is not new in 1.6, is it?
I have never considered putting 3 stairs next to each other like this. The hero can only use one of them at a time, so the behavior is expected.

2 solutions:
- You could try making a stairs entity of size 48x16, because in 1.6, all entities can have any size. But for stairs you can only change the size from a script, and more importantly, it was never tested.
- Do you even need a stairs entity at all? You can use sensors instead to change the layer of the hero.
Title: Re: Weird Stairs Issue
Post by: Max on December 23, 2018, 12:31:05 am
It  actually is new to 1.6. I just opened up an old version of my game in 1.5 and there's no issues, tried the same staircase. I wonder what changed that it stopped working?

I'll figure out sensors then. What is the behavior of stairs besides some code like:
Code: (Lua) [Select]
function stair_sensor:on_activated()
 Hero:set_layer(hero:get_layer() +1)
end

Is forcing movement on the hero important, or if you don't make the hero move also will they just fall right back down immediately. Well, I guess I'll try it after I make some dinner and figure that out, lol
Title: Re: Weird Stairs Issue
Post by: Max on December 25, 2018, 05:23:41 pm
Here's the results of using a sensor that does
Code: [Select]
for sensor in map:get_entities("stair_sensor") do
  function sensor:on_activated()
    hero:set_layer(hero:get_layer() + 1)
  end
end

(https://i.imgur.com/KUXjL0S.gif)

Has anyone used sensors to move up layers and not had an issue with tiles on the upper layer overlapping the hero? How did you overcome that?

Also, just an observation from experimenting with the way stair entities work between 1.5 and 1.6- even if you just put a stair in the middle of an empty field in 1.5, you don't have to be perfectly aligned with it for the stair action to work. But in 1.6 even if a stair in the middle of a field, you have to be perfectly lined up with the tile for the stairs to do their thing.
Title: Re: Weird Stairs Issue
Post by: Christopho on December 25, 2018, 08:27:11 pm
This tutorial explains how to change the layer using sensors: https://www.youtube.com/watch?v=bXQ7WGK8kvg
Title: Re: Weird Stairs Issue
Post by: alexgleason on December 25, 2018, 11:04:09 pm
Here's my solution in VOADI: https://gitlab.com/voadi/voadi/blob/master/data/maps/overworld.lua#L63-78

Code: [Select]
  do
    local sensor = map:get_entity("bridge_1")
    function sensor:on_activated()
      local x, y, z = hero:get_position()
      hero:set_position(x, y, 1)
      log("Hero moved to L1: ", hero:get_position())
    end
  end
  do
    local sensor = map:get_entity("bridge_2")
    function sensor:on_activated()
      local x, y, z = hero:get_position()
      hero:set_position(x, y, 0)
      log("Hero moved to L0: ", hero:get_position())
    end
  end

Here's how it looks on my map:

(https://i.imgur.com/KOyZkGm.png)

And the same spot with layer 2 hidden:

(https://i.imgur.com/bwrWczM.png)

Would be even better to encapsulate this behavior into a custom entity that automatically creates the needed sensors.
Title: Re: Weird Stairs Issue
Post by: alexgleason on December 25, 2018, 11:05:44 pm
Oh sorry, I think I replied before fully understanding. Also I should have used hero:set_layer which I didn't know about.

I don't have this issue in my game, but my character sprite is also only 16px tall.
Title: Re: Weird Stairs Issue
Post by: Diarandor on December 27, 2018, 11:29:33 am
The functions entity.get/set_layer are new in v1.6, so it is normal that you didn't know that one.
Title: Re: Weird Stairs Issue
Post by: alexgleason on December 30, 2018, 06:39:49 pm
I forgot to mention, in my example I also have an invisible platform on layer 1 so the hero doesn't fall through once the sensor lifts her up.

I need something like this again so I'm working on creating a script to make it happen automatically.
Title: Re: Weird Stairs Issue
Post by: Diarandor on December 31, 2018, 12:38:29 am
We should have mentioned the tutorial of @ffomega related to this (in the Bridges section):
http://absolute-hyrule-tutorials.solarus-games.org/
Title: Re: Weird Stairs Issue
Post by: Max on December 31, 2018, 03:45:22 pm
Thanks guys. I followed Christopho's tutorials, and now I've got it so I only need five tiles which I can copy from my debug map each time and the event is handled with metatables, which isn't too bad. However it still feels a little hacked together, since a function as basic as changing layers needs such a complex solution when I could just use stairs before, haha.

But I never liked how the automatic stairs took control away from the player so that's nice that it addresses that too! Now to just do this for dozens of stairs in my game, hahaha........
Title: Re: Weird Stairs Issue
Post by: alexgleason on December 31, 2018, 03:58:44 pm
At the very least, you can create a custom entity that calls map:create_custom_entity() and automatically creates the two sensors and the invisible tile wherever you place it.
Title: Re: Weird Stairs Issue
Post by: Max on January 01, 2019, 03:58:40 pm
What's a good idea, Alex! It could get the width for the stairs from it's own width, then create the sensors and invisible platform at it's coordinates. Good thinking.


Anyway, I was looking at the change log for 1.6 on the website's blog about the release, and saw this line:
Quote
Fix stairs activating when the hero is not exactly aligned.

And realized that's exactly what changed. Is there any way to un-fix this so I can make the behavior of my stairs back how it was?
Title: Re: Weird Stairs Issue
Post by: Christopho on January 01, 2019, 04:26:37 pm
The old behavior was a bug. But did you try to make a single stairs entity with a size of 48x16? (You need to do it from a script)
Title: Re: Weird Stairs Issue
Post by: Diarandor on January 01, 2019, 09:09:28 pm
The old behavior was a bug. But did you try to make a single stairs entity with a size of 48x16? (You need to do it from a script)
I guess it will be possible to resize stairs in future versions of solarus, right?

If he needs to resize the stairs from scripts, the best way is probably to define the size using custom properties in the editor, and re-define the event "stairs_metatable:on_created()" to use those custom properties to resize the stairs when they are given.
Or even better, maybe he should use custom entities that auto-replace themselves with stairs of the same size, so that he can resize them and see their size in the editor.
Title: Re: Weird Stairs Issue
Post by: Max on January 02, 2019, 03:21:04 am
I tried it, and unfortunately, although you can resize stairs to whatever size you want, they only activate when the hero is exactly lined up with the position of the 16x16 entity. The rest of the large stairs entity just operates as an invisible wall.
Title: Re: Weird Stairs Issue
Post by: Christopho on January 02, 2019, 08:15:54 pm
Ok, can you open a gitlab issue? I will try to fix it in 1.6.1.
Title: Re: Weird Stairs Issue
Post by: alexgleason on April 24, 2019, 06:33:42 pm
I placed a $5 bounty on solving this issue using a single custom entity: https://gitlab.com/voadi/voadi/issues/106
Title: Re: Weird Stairs Issue
Post by: Cluedrew on April 27, 2019, 10:49:19 pm
Was an issue for the engine side problem created? I can't find it if one was.