From 532af0c9220c3150070b12607cd5ff03b098c366 Mon Sep 17 00:00:00 2001 From: Alexsandro Percy Date: Mon, 17 Jan 2022 10:34:44 -0300 Subject: [PATCH] ramp collision improved --- automobiles/ground_detection.lua | 27 +++++++++++++++------- automobiles_roadster/roadster_entities.lua | 2 +- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/automobiles/ground_detection.lua b/automobiles/ground_detection.lua index 058ce39..053c862 100644 --- a/automobiles/ground_detection.lua +++ b/automobiles/ground_detection.lua @@ -8,7 +8,7 @@ proximo experimento sera mis complexo: pegar o yaw do carro, colocar o entreeixo function automobiles.ground_get_distances(self, radius, axis_distance) --local mid_axis = (axis_length / 2)/10 - local hip = (axis_distance / 10) + local hip = axis_distance --minetest.chat_send_all("entre-eixo "..hip) local pitch = self._pitch --+90 for the calculations @@ -51,7 +51,7 @@ function automobiles.ground_get_distances(self, radius, axis_distance) local deltaX = axis_distance; local deltaY = front_obstacle_level.y - rear_obstacle_level.y; --minetest.chat_send_all("deutaY "..deltaY) - local m = (deltaY/deltaX)*10 + local m = (deltaY/deltaX) pitch = math.atan(m) --math.atan2(deltaY, deltaX); --minetest.chat_send_all("m: "..m.." pitch ".. math.deg(pitch)) self._pitch = pitch @@ -73,13 +73,20 @@ function automobiles.get_obstacle(ref_pos) local i_pos = {x=ref_pos.x, y=ref_pos.y, z=ref_pos.z} --minetest.chat_send_all("bb y: " .. dump(retval.y)) - retval.y = eval_interception(i_pos, {x=i_pos.x, y=i_pos.y - 2, z=i_pos.z}) + retval.y = automobiles.eval_interception(i_pos, {x=i_pos.x, y=i_pos.y - 2, z=i_pos.z}) --minetest.chat_send_all("y: " .. dump(ref_pos.y) .. " ye: ".. dump(retval.y)) return retval end -function eval_interception(initial_pos, end_pos) +local function get_nodedef_field(nodename, fieldname) + if not minetest.registered_nodes[nodename] then + return nil + end + return minetest.registered_nodes[nodename][fieldname] +end + +function automobiles.eval_interception(initial_pos, end_pos) local ret_y = nil local cast = minetest.raycast(initial_pos, end_pos, true, false) local thing = cast:next() @@ -87,10 +94,14 @@ function eval_interception(initial_pos, end_pos) if thing.type == "node" then local pos = thing.intersection_point if pos then - ret_y = pos.y - --local node_name = minetest.get_node(thing.under).name - --minetest.chat_send_all("ray intercection: " .. dump(pos.y) .. " -- " .. node_name) - break + local nodename = minetest.get_node(thing.under).name + local drawtype = get_nodedef_field(nodename, "drawtype") + if drawtype ~= "plantlike" then + ret_y = pos.y + --local node_name = node.name + --minetest.chat_send_all("ray intercection: " .. dump(pos.y) .. " -- " .. node_name) + break + end end end thing = cast:next() diff --git a/automobiles_roadster/roadster_entities.lua b/automobiles_roadster/roadster_entities.lua index cd6d2d2..b68915f 100755 --- a/automobiles_roadster/roadster_entities.lua +++ b/automobiles_roadster/roadster_entities.lua @@ -433,7 +433,7 @@ minetest.register_entity("automobiles_roadster:roadster", { self._steering_angle / 30 * turn_rate * automobiles.sign(longit_speed) end - automobiles.ground_get_distances(self, 0.5, 24.22) + automobiles.ground_get_distances(self, 0.5, 2.422) --[[if player and is_attached then player:set_look_horizontal(newyaw)