mirror of
https://github.com/APercy/automobiles_pck
synced 2025-08-18 02:45:48 +02:00
added collision in front axis
This commit is contained in:
parent
881db52904
commit
e6fbd5d400
@ -559,18 +559,6 @@ minetest.register_entity("automobiles_buggy:buggy", {
|
||||
self._steering_angle / 30 * turn_rate * automobiles_lib.sign(longit_speed)
|
||||
end
|
||||
|
||||
self._last_ground_check = self._last_ground_check + dtime
|
||||
if self._last_ground_check > 0.18 then
|
||||
self._last_ground_check = 0
|
||||
automobiles_lib.ground_get_distances(self, 0.372, 2.3)
|
||||
end
|
||||
|
||||
--[[if player and is_attached then
|
||||
player:set_look_horizontal(newyaw)
|
||||
end]]--
|
||||
|
||||
local newpitch = self._pitch --velocity.y * math.rad(6)
|
||||
|
||||
--[[
|
||||
accell correction
|
||||
under some circunstances the acceleration exceeds the max value accepted by set_acceleration and
|
||||
@ -622,6 +610,13 @@ minetest.register_entity("automobiles_buggy:buggy", {
|
||||
end
|
||||
end
|
||||
|
||||
self._last_ground_check = self._last_ground_check + dtime
|
||||
if self._last_ground_check > 0.18 then
|
||||
self._last_ground_check = 0
|
||||
automobiles_lib.ground_get_distances(self, 0.372, 2.3)
|
||||
end
|
||||
local newpitch = self._pitch --velocity.y * math.rad(6)
|
||||
|
||||
if newyaw~=yaw or newpitch~=pitch then self.object:set_rotation({x=newpitch,y=newyaw,z=0}) end
|
||||
|
||||
--saves last velocity for collision detection (abrupt stop)
|
||||
|
@ -586,19 +586,6 @@ minetest.register_entity("automobiles_coupe:coupe", {
|
||||
self._turn_light_timer = 1
|
||||
end
|
||||
|
||||
|
||||
self._last_ground_check = self._last_ground_check + dtime
|
||||
if self._last_ground_check > 0.18 then
|
||||
self._last_ground_check = 0
|
||||
automobiles_lib.ground_get_distances(self, 0.372, 2.3)
|
||||
end
|
||||
|
||||
--[[if player and is_attached then
|
||||
player:set_look_horizontal(newyaw)
|
||||
end]]--
|
||||
|
||||
local newpitch = self._pitch --velocity.y * math.rad(6)
|
||||
|
||||
--[[
|
||||
accell correction
|
||||
under some circunstances the acceleration exceeds the max value accepted by set_acceleration and
|
||||
@ -650,6 +637,13 @@ minetest.register_entity("automobiles_coupe:coupe", {
|
||||
end
|
||||
end
|
||||
|
||||
self._last_ground_check = self._last_ground_check + dtime
|
||||
if self._last_ground_check > 0.18 then
|
||||
self._last_ground_check = 0
|
||||
automobiles_lib.ground_get_distances(self, 0.372, 2.3)
|
||||
end
|
||||
local newpitch = self._pitch --velocity.y * math.rad(6)
|
||||
|
||||
if newyaw~=yaw or newpitch~=pitch then self.object:set_rotation({x=newpitch,y=newyaw,z=0}) end
|
||||
|
||||
--saves last velocity for collision detection (abrupt stop)
|
||||
|
@ -1,6 +1,5 @@
|
||||
--lets assume that the rear axis is at object center, so we will use the distance only for front wheels
|
||||
function automobiles_lib.ground_get_distances(self, radius, axis_distance)
|
||||
|
||||
--local mid_axis = (axis_length / 2)/10
|
||||
local hip = axis_distance
|
||||
--minetest.chat_send_all("entre-eixo "..hip)
|
||||
@ -21,6 +20,10 @@ function automobiles_lib.ground_get_distances(self, radius, axis_distance)
|
||||
local rear_obstacle_level = automobiles_lib.get_obstacle(rear_axis)
|
||||
--minetest.chat_send_all("rear"..dump(rear_obstacle_level))
|
||||
|
||||
if not self._last_front_detection then
|
||||
self._last_front_detection = rear_obstacle_level.y
|
||||
end
|
||||
|
||||
local f_x, f_z = automobiles_lib.get_xz_from_hipotenuse(pos.x, pos.z, yaw, hip)
|
||||
local f_y = pos.y
|
||||
--local x, f_y = automobiles_lib.get_xz_from_hipotenuse(f_x, r_y, pitch - math.rad(90), hip) --the x is only a mock
|
||||
@ -56,29 +59,36 @@ function automobiles_lib.ground_get_distances(self, radius, axis_distance)
|
||||
|
||||
--lets try to get the pitch
|
||||
if front_obstacle_level.y ~= nil and rear_obstacle_level.y ~= nil then
|
||||
local deltaX = axis_distance;
|
||||
local deltaY = front_obstacle_level.y - rear_obstacle_level.y;
|
||||
--minetest.chat_send_all("deutaY "..deltaY)
|
||||
local m = (deltaY/deltaX)
|
||||
pitch = math.atan(m) --math.atan2(deltaY, deltaX);
|
||||
--minetest.chat_send_all("m: "..m.." pitch ".. math.deg(pitch))
|
||||
|
||||
--[[if mid_car_level then
|
||||
deltaX = axis_distance/2;
|
||||
if mid_car_level.y ~= nil then
|
||||
local deltaY_mid = mid_car_level.y - rear_obstacle_level.y;
|
||||
if deltaY >= 1 and deltaY_mid < (deltaY / 2) then
|
||||
--self.initial_properties.stepheight
|
||||
pitch = math.rad(0)
|
||||
end
|
||||
--[[m = (deltaY_mid/deltaX)
|
||||
local midpitch = math.atan(m)
|
||||
if math.abs(math.deg(pitch) - math.deg(midpitch)) < 20 then
|
||||
pitch = pitch + ((pitch - midpitch) / 2)
|
||||
end]]--
|
||||
--[[end
|
||||
end]]--
|
||||
if (front_obstacle_level.y-self._last_front_detection) <= self.initial_properties.stepheight then
|
||||
self._last_front_detection = front_obstacle_level.y
|
||||
local deltaX = axis_distance;
|
||||
local deltaY = front_obstacle_level.y - rear_obstacle_level.y;
|
||||
--minetest.chat_send_all("deutaY "..deltaY)
|
||||
local m = (deltaY/deltaX)
|
||||
pitch = math.atan(m) --math.atan2(deltaY, deltaX);
|
||||
--minetest.chat_send_all("m: "..m.." pitch ".. math.deg(pitch))
|
||||
|
||||
--[[if mid_car_level then
|
||||
deltaX = axis_distance/2;
|
||||
if mid_car_level.y ~= nil then
|
||||
local deltaY_mid = mid_car_level.y - rear_obstacle_level.y;
|
||||
if deltaY >= 1 and deltaY_mid < (deltaY / 2) then
|
||||
--self.initial_properties.stepheight
|
||||
pitch = math.rad(0)
|
||||
end
|
||||
--[[m = (deltaY_mid/deltaX)
|
||||
local midpitch = math.atan(m)
|
||||
if math.abs(math.deg(pitch) - math.deg(midpitch)) < 20 then
|
||||
pitch = pitch + ((pitch - midpitch) / 2)
|
||||
end]]--
|
||||
--[[end
|
||||
end]]--
|
||||
else
|
||||
self._last_front_detection = rear_obstacle_level.y
|
||||
--here we need to set the collision effect
|
||||
self.object:set_acceleration({x=0,y=0,z=0})
|
||||
self.object:set_velocity({x=0,y=0,z=0})
|
||||
end
|
||||
else
|
||||
pitch = math.rad(0)
|
||||
end
|
||||
|
@ -532,18 +532,6 @@ minetest.register_entity("automobiles_roadster:roadster", {
|
||||
self._steering_angle / 30 * turn_rate * automobiles_lib.sign(longit_speed)
|
||||
end
|
||||
|
||||
self._last_ground_check = self._last_ground_check + dtime
|
||||
if self._last_ground_check > 0.18 then
|
||||
self._last_ground_check = 0
|
||||
automobiles_lib.ground_get_distances(self, 0.5, 2.422)
|
||||
end
|
||||
|
||||
--[[if player and is_attached then
|
||||
player:set_look_horizontal(newyaw)
|
||||
end]]--
|
||||
|
||||
local newpitch = self._pitch --velocity.y * math.rad(6)
|
||||
|
||||
--[[
|
||||
accell correction
|
||||
under some circunstances the acceleration exceeds the max value accepted by set_acceleration and
|
||||
@ -595,6 +583,13 @@ minetest.register_entity("automobiles_roadster:roadster", {
|
||||
end
|
||||
end
|
||||
|
||||
self._last_ground_check = self._last_ground_check + dtime
|
||||
if self._last_ground_check > 0.18 then
|
||||
self._last_ground_check = 0
|
||||
automobiles_lib.ground_get_distances(self, 0.5, 2.422)
|
||||
end
|
||||
local newpitch = self._pitch --velocity.y * math.rad(6)
|
||||
|
||||
if newyaw~=yaw or newpitch~=pitch then self.object:set_rotation({x=newpitch,y=newyaw,z=0}) end
|
||||
|
||||
--saves last velocity for collision detection (abrupt stop)
|
||||
|
Loading…
Reference in New Issue
Block a user