joe7575 / signs_bot

A Minetest robot controlled by signs
GNU General Public License v3.0
5 stars 7 forks source link

Fall_Down results in bot landing inside solid node #44

Closed Eternal-Study closed 2 months ago

Eternal-Study commented 2 months ago

When the fall_down command is used, the bot will land inside of the first solid node in its path instead of on top of it. Once the bot moves, the node reappears. However, the bot still completes its fall one node lower than expected.

This is due to minetest.line_of_sight returning the coordinates of the first solid node in the path, causing to bot to finish its fall at the coordinates of the sold node, instead of one node above it.

This also results in the bot falling no more than 9 nodes instead of the documented 10. The node directly below the bot has a y value of robot_pos.y-1. Therefore the "floor" of a 10 node drop should have a value of robot_pos.y-1-10 = robot_pos.y-11.

How to Test

1) Build a 10 node high tower with the bot box and a command sign on top. 2) Program the sign to instruct the bot to move to the edge of the tower, then execute the fall_down command. 3) Observe it will not follow the command. 4) Add 1-2 nodes to the bottom of the tower where the bot should fall. 5) Observe the bot falls now, but displaces the node it falls on.

Steps to Fix

Pull request #45 addresses this issue.

joe7575 commented 2 months ago

But it has always worked so far. What is different about your setup? https://www.youtube.com/watch?v=KcMC78mKw3c

Eternal-Study commented 2 months ago

Judging by the Minetest version number in the video, I believe the video was recorded prior to commit 625fd58, which removed the "+1" to the pos3.y value in line 275.

I performed my tests again but this time had the bot fall onto nodes with the "walkable" property set to false. I confirmed that when falling onto a non-walkable node, pull request #45 introduce a bug where the node the bot falls onto is broken, and a clone of the bot is left in its place.

I'll work on the problem and see if there is a solution that addresses both issues.

Eternal-Study commented 2 months ago

I have identified the cause of the issues. The code uses “minetest.line_of_sight(pos1, pos2)” to check if there are any nodes to land on and where the bot will land. It then uses “minetest.spawn_falling_node(mem.robot_pos)” to generate the falling node.

However, line_of_sight returns the first node that is not “air”, while falling nodes will go through any node with the “walkable=false” property. In some situations, this can lead to the code placing the bot in one location, but the falling node stops at another.

screenshot_20240726_200040

In the attached image, that the current version of the code has created two bots. An immobile one at the bottom of the tower, and a 2nd at the level of the sign (note: the bot must move to become visible).

screenshot_20240726_200205

A similar effect can be caused by placing a sign two blocks above the ground.

I’ve updated the pull request so instead of using line_of_sight, it instead uses a loop to check each node for one that is walkable.