mirror of
https://github.com/APercy/automobiles_pck
synced 2025-11-22 06:27:58 +01:00
position and smooth
This commit is contained in:
parent
60afdb8676
commit
a23a5938bc
@ -28,6 +28,14 @@ function automobiles_lib.ground_get_distances(self, radius, axis_distance)
|
|||||||
local front_obstacle_level = automobiles_lib.get_obstacle(front_axis)
|
local front_obstacle_level = automobiles_lib.get_obstacle(front_axis)
|
||||||
--minetest.chat_send_all("front"..dump(front_obstacle_level))
|
--minetest.chat_send_all("front"..dump(front_obstacle_level))
|
||||||
|
|
||||||
|
--[[ here lets someting to smooth the detection using the middle os the car as reference]]--
|
||||||
|
f_x, f_z = automobiles_lib.get_xz_from_hipotenuse(pos.x, pos.z, yaw, hip/2)
|
||||||
|
x, f_y = automobiles_lib.get_xz_from_hipotenuse(f_x, r_y, pitch - math.rad(90), hip/2) --the x is only a mock
|
||||||
|
--minetest.chat_send_all("r: "..r_y.." f: "..f_y .." - "..math.deg(pitch))
|
||||||
|
local mid_car = {x=f_x, y=f_y, z=f_z}
|
||||||
|
local mid_car_level = automobiles_lib.get_obstacle(mid_car)
|
||||||
|
|
||||||
|
|
||||||
--[[local left_front = {x=0, y=f_y, z=0}
|
--[[local left_front = {x=0, y=f_y, z=0}
|
||||||
left_front.x, left_front.z = automobiles_lib.get_xz_from_hipotenuse(f_x, f_z, yaw+math.rad(90), mid_axis)
|
left_front.x, left_front.z = automobiles_lib.get_xz_from_hipotenuse(f_x, f_z, yaw+math.rad(90), mid_axis)
|
||||||
|
|
||||||
@ -52,6 +60,16 @@ function automobiles_lib.ground_get_distances(self, radius, axis_distance)
|
|||||||
local m = (deltaY/deltaX)
|
local m = (deltaY/deltaX)
|
||||||
pitch = math.atan(m) --math.atan2(deltaY, deltaX);
|
pitch = math.atan(m) --math.atan2(deltaY, deltaX);
|
||||||
--minetest.chat_send_all("m: "..m.." pitch ".. math.deg(pitch))
|
--minetest.chat_send_all("m: "..m.." pitch ".. math.deg(pitch))
|
||||||
|
|
||||||
|
if mid_car_level then
|
||||||
|
deltaX = axis_distance/2;
|
||||||
|
deltaY = mid_car_level.y - rear_obstacle_level.y;
|
||||||
|
m = (deltaY/deltaX)
|
||||||
|
local midpitch = math.atan(m)
|
||||||
|
if math.abs(math.deg(pitch) - math.deg(midpitch)) < 20 then
|
||||||
|
pitch = pitch + ((pitch - midpitch) / 2)
|
||||||
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
self._pitch = 0
|
self._pitch = 0
|
||||||
end
|
end
|
||||||
|
|||||||
@ -69,8 +69,7 @@ function automobiles_lib.attach_driver(self, player)
|
|||||||
|
|
||||||
-- attach the driver
|
-- attach the driver
|
||||||
player:set_attach(self.driver_seat, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
player:set_attach(self.driver_seat, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
||||||
player:set_eye_offset({x = 0, y = -4, z = 2}, {x = 0, y = 1, z = -30})
|
player:set_eye_offset({x = 0, y = -4, z = 0}, {x = 0, y = 1, z = -30})
|
||||||
player:set_eye_offset({x = 0, y = -4, z = 2}, {x = 0, y = 1, z = -30})
|
|
||||||
player_api.player_attached[name] = true
|
player_api.player_attached[name] = true
|
||||||
-- make the driver sit
|
-- make the driver sit
|
||||||
minetest.after(0.2, function()
|
minetest.after(0.2, function()
|
||||||
@ -122,7 +121,7 @@ function automobiles_lib.attach_pax(self, player, onside)
|
|||||||
|
|
||||||
-- attach the driver
|
-- attach the driver
|
||||||
player:set_attach(self.passenger_seat, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
player:set_attach(self.passenger_seat, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
||||||
player:set_eye_offset({x = 0, y = -4, z = 2}, {x = 0, y = 3, z = -30})
|
player:set_eye_offset({x = 0, y = -4, z = 0}, {x = 0, y = 3, z = -30})
|
||||||
player_api.player_attached[name] = true
|
player_api.player_attached[name] = true
|
||||||
-- make the driver sit
|
-- make the driver sit
|
||||||
minetest.after(0.2, function()
|
minetest.after(0.2, function()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user