Trouble making a bridge.

Started by Zeror, July 30, 2015, 12:59:00 AM

Previous topic - Next topic
I've troubles with creating a bridge.

I want Link to be walk underneath and over it. So Link walks underneath he walks on the low layer. And over the bridge he walks on the intermediate layer.
So i wanted to change the layer of the hero to intermediate when he walk across the bridge.

I was thinking of creating a sensor for it, but i have no idea how. A way of doing it i was thinking of was to check if the hero is on a layer and then change it the other. So if on low > set hero on intermediate. If on intermediate > set hero on low layer. And then place the same sensor on both ends of the bridge.

How do i do that in LUA?

July 30, 2015, 01:16:31 AM #1 Last Edit: July 30, 2015, 01:25:02 AM by DementedKirby
Remember that if you change the hero's layer and not the tile's layer, the hero may disappear of strange things may happen if you don't have any corresponding tiles above or below. How about using dynamic layers that appear or disappear as you traverse the sensor?

I'm pretty sure that with just having tiles beneath the bridge in low layer and making the bridge intermediate layer you should get the effect that you want. However, you need a stairs type entity to traverse between layers in an easy manner.

However, if you're dead set on moving up or down a layer forcefully, you could use the sensor to simply change the layer. An example:
function layer_change:on_activated() -- layer_change is a sensor
   local x, y, layer = hero:get_position()
   if layer == 0 then
      hero:set_position(x,y,0)
   else
      hero:set_position(x,y,1)
end


That should work. You could use that on an area on the map that looks like you're going up or down a hill to visualize the change of layer.

EDIT:
To make the transition smoother, you could dedicate one sensor each per layer change. That way you can make sure it happens smoothly.

Christopho made a bridge in zelda mercuris chest (under development).

You can see an example in `the forest_store` map. He use sensors named `layer_up_sensor` and `layer_down_sensor`, you can find the code to make that in the quest_manager.lua script.
SQE developer

Tried both methods, but somehow it does not work.

Copied this from Christopho's Mercury Chest to check out if it works.
Named the sensors "to_layer_up_sensor" and "to_layer_down_sensor", but it doesn't not change the layer when the hero walk on it.
-- Initialize sensor behavior specific to this quest.
local function initialize_sensor()

  local sensor_meta = sol.main.get_metatable("sensor")

  function sensor_meta:on_activated()

    local game = self:get_game()
    local hero = self:get_map():get_hero()
    local name = self:get_name()

    -- Sensors named "to_layer_X_sensor" move the hero on that layer.
    -- TODO use a custom entity or a wall to block enemies and thrown items?
    if name:match("^layer_up_sensor") then
      local x, y, layer = hero:get_position()
      if layer < 2 then
        hero:set_position(x, y, layer + 1)
      end
    elseif name:match("^layer_down_sensor") then
      local x, y, layer = hero:get_position()
      if layer > 0 then
        hero:set_position(x, y, layer - 1)
      end
    end

  end
end

Do you have put sensors on good layers? And have you noticed that he uses invisible tiles placed on the upper layer to allow the transition?
SQE developer

I've loaded the Forest store map of Christopho in my quest, but the layer changing system he made doesn't work there either. I've noticed the invisible tile, but i am not certain about it's purpose.

Let me show my situation:



The top sensor should be the one to go a layer down, and the lower sensor should be the one to go a layer up.

There is some code in script/quest_manager.lua that do the work for all sensors called to_layer_up_sensor and to_layer_down_sensor. This is probably what is missing for you.

But the bridge in Mercuris' Chest forest map, is a bad example, it is over-complicated due to diagonal stair tiles.

A better example is the map rail_temple/1f instead (still in Mercuris), where the layer changes when the hero walks on slopes that replace usual stairs. There is no bridge but your can see how to change the layer without the player noticing. I use an invisible tile indeed, to solve the problem you mentioned:
QuoteRemember that if you change the hero's layer and not the tile's layer, the hero may disappear of strange things may happen if you don't have any corresponding tiles above or below
The invisible tile is on the higher layer of both, it is walkable so that the hero does not fall. Then two sensors do the trick. They should not overlap each other, otherwise you would have an infinite loop.

July 30, 2015, 11:17:20 AM #7 Last Edit: July 30, 2015, 11:42:03 AM by Diarandor
Hi! I was thinking that the bridge would not work correctly with enemies and thrown entities (like arrows). But if we use a custom entity with a collision test instead of the sensor, that could be done. (Anyway, this matter is not really important, since most of the players would not realize of the problem.)

EDIT: if the hero has a companion that follows him, it could be necessary to use the custom entity collision and not the sensor.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

Quote from: Christopho on July 30, 2015, 10:53:49 AM
There is some code in script/quest_manager.lua that do the work for all sensors called to_layer_up_sensor and to_layer_down_sensor. This is probably what is missing for you.

But the bridge in Mercuris' Chest forest map, is a bad example, it is over-complicated due to diagonal stair tiles.

A better example is the map rail_temple/1f instead (still in Mercuris), where the layer changes when the hero walks on slopes that replace usual stairs. There is no bridge but your can see how to change the layer without the player noticing.
I did exactly like you did in the rail temple map, but it still doesn't work. I tried to name them to_layer_up_sensor and to_layer_down_sensor and layer_up_sensor and layer_down_sensor, but both did not work.

This is the code i've copied and used
-- Initialize sensor behavior specific to this quest.
local function initialize_sensor()

  local sensor_meta = sol.main.get_metatable("sensor")

    function sensor_meta:on_activated()

    local game = self:get_game()
    local hero = self:get_map():get_hero()
    local name = self:get_name()

    -- Sensors named "to_layer_X_sensor" move the hero on that layer.
    -- TODO use a custom entity or a wall to block enemies and thrown items?
    if name:match("^layer_up_sensor") then
      local x, y, layer = hero:get_position()
      if layer < 2 then
        hero:set_position(x, y, layer + 1)
      end
    elseif name:match("^layer_down_sensor") then
      local x, y, layer = hero:get_position()
      if layer > 0 then
        hero:set_position(x, y, layer - 1)
      end
    end

  end

end

Got it located in the game_manager script.

I really don't understand anymore what the problem is.... Tried to place the sensors in several ways if that would matter. Sensor down is on the intermediate layer and sensor up on the low layer.

:-[

Make the entire part you want in low layer then above it make the exact same tiles in intermediate layer. That way when you change from one to the other, the hero appears accordingly. I think your error is more graphical than "scriptical".

There is something you must know (but I don't know if you know it, since it has not been explained here with all details yet). If the hero walks over an intermediate layer (or high) and the tile ends, he "falls" to the low layer immediately. (Maybe you already knew it.) I suppose that the purpose of the transparent tile is to keep the hero on the intermediate layer after his position is changed by the sensor on low (so the transparent layer starts above the sensor on low, covering it, and connects with the other intermediate layer tiles).

(I was thinking that the sensor above, which changes hero's position to the lower one, is not necessary at all, since the hero "falls" automatically in the border of the transparent tile.)
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

I don't see the hero changing to the intermediate layer. It stays on the low layer and dissappears behind the intermediate layer of the bridge.

Here is a detailed view on my current situation:


Your 3 pictures look correct to me (gg for the very detailed pictures, by the way).

The code of quest_manager works for layers whose name start with layer_up_sensor or layer_down_sensor. Not to_layer_up_sensor/to_layer_down_sensor.

Try to put some print statements in the sensor_meta:on_activated() method just to see if it gets called and if yes, why it does not make its job.


Your example doesn't work in my project.

I'm getting the idea that something else not related to this problem, but to Solarus itself might be a problem. I don't know why.