Author Topic: Trouble making a bridge.  (Read 5427 times)

Zeror

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
Trouble making a bridge.
« on: July 30, 2015, 12:59:00 am »
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?

DementedKirby

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
Re: Trouble making a bridge.
« Reply #1 on: July 30, 2015, 01:16:31 am »
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:
Code: [Select]
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.
« Last Edit: July 30, 2015, 01:25:02 am by DementedKirby »

Maxs

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Trouble making a bridge.
« Reply #2 on: July 30, 2015, 01:23:55 am »
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

Zeror

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
Re: Trouble making a bridge.
« Reply #3 on: July 30, 2015, 02:35:05 am »
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.
Code: [Select]
-- 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

Maxs

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Trouble making a bridge.
« Reply #4 on: July 30, 2015, 02:54:38 am »
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

Zeror

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
Re: Trouble making a bridge.
« Reply #5 on: July 30, 2015, 08:54:49 am »
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.

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1177
    • View Profile
Re: Trouble making a bridge.
« Reply #6 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 use an invisible tile indeed, to solve the problem you mentioned:
Quote
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
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.

Diarandor

  • Hero Member
  • *****
  • Posts: 1052
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Trouble making a bridge.
« Reply #7 on: July 30, 2015, 11:17:20 am »
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.
« Last Edit: July 30, 2015, 11:42:03 am by Diarandor »
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

Zeror

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
Re: Trouble making a bridge.
« Reply #8 on: July 30, 2015, 03:25:35 pm »
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
Code: [Select]
-- 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.

 :-[

DementedKirby

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
Re: Trouble making a bridge.
« Reply #9 on: July 30, 2015, 07:17:55 pm »
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".

Diarandor

  • Hero Member
  • *****
  • Posts: 1052
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Trouble making a bridge.
« Reply #10 on: July 30, 2015, 09:40:32 pm »
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.”

Zeror

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
Re: Trouble making a bridge.
« Reply #11 on: July 31, 2015, 10:40:29 am »
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:


Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1177
    • View Profile
Re: Trouble making a bridge.
« Reply #12 on: July 31, 2015, 01:08:38 pm »
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.

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1177
    • View Profile
Re: Trouble making a bridge.
« Reply #13 on: July 31, 2015, 01:55:57 pm »
I just made an example of bridge. It should help!

Zeror

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
Re: Trouble making a bridge.
« Reply #14 on: July 31, 2015, 03:29:30 pm »
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.