mirror of
https://github.com/APercy/automobiles_pck
synced 2025-06-15 13:28:02 +02:00
ramp collision improved nd added a horn
This commit is contained in:
parent
532af0c922
commit
fa64ff51d7
@ -34,28 +34,15 @@ function automobiles.control(self, dtime, hull_direction, longit_speed, longit_d
|
||||
local ctrl = player:get_player_control()
|
||||
|
||||
local acc = 0
|
||||
if self._engine_running then
|
||||
--running
|
||||
if longit_speed < max_speed and ctrl.up then
|
||||
--get acceleration factor
|
||||
acc = automobiles.check_road_is_ok(self.object, max_acc_factor)
|
||||
--minetest.chat_send_all('engineacc: '.. engineacc)
|
||||
if acc > 1 and acc < max_acc_factor and longit_speed > 0 then
|
||||
--improper road will reduce speed
|
||||
acc = -1
|
||||
end
|
||||
end
|
||||
else
|
||||
--slow maneuver
|
||||
if longit_speed < roadster.max_speed and ctrl.up then
|
||||
--get acceleration factor
|
||||
acc = automobiles.check_road_is_ok(self.object, max_acc_factor)
|
||||
--minetest.chat_send_all('engineacc: '.. engineacc)
|
||||
if acc > 1 and acc < max_acc_factor and longit_speed > 0 then
|
||||
--improper road will reduce speed
|
||||
acc = -1
|
||||
end
|
||||
end
|
||||
|
||||
if longit_speed < roadster.max_speed and ctrl.up then
|
||||
--get acceleration factor
|
||||
acc = automobiles.check_road_is_ok(self.object, max_acc_factor)
|
||||
--minetest.chat_send_all('engineacc: '.. engineacc)
|
||||
if acc > 1 and acc < max_acc_factor and longit_speed > 0 then
|
||||
--improper road will reduce speed
|
||||
acc = -1
|
||||
end
|
||||
end
|
||||
|
||||
--reversing
|
||||
@ -65,9 +52,6 @@ function automobiles.control(self, dtime, hull_direction, longit_speed, longit_d
|
||||
|
||||
--break
|
||||
if ctrl.down then
|
||||
--[[if math.abs(longit_speed) > 0 then
|
||||
acc = -5 / (longit_speed / 2) -- lets set a brake efficience based on speed
|
||||
end]]--
|
||||
|
||||
--total stop
|
||||
--wheel break
|
||||
@ -90,30 +74,6 @@ function automobiles.control(self, dtime, hull_direction, longit_speed, longit_d
|
||||
|
||||
if acc then retval_accel=vector.add(accel,vector.multiply(hull_direction,acc)) end
|
||||
|
||||
if ctrl.aux1 then
|
||||
--[[
|
||||
--sets the engine running - but sets a delay also, cause keypress
|
||||
if self._last_time_command > 0.3 then
|
||||
self._last_time_command = 0
|
||||
if self._engine_running then
|
||||
self._engine_running = false
|
||||
-- sound and animation
|
||||
if self.sound_handle then
|
||||
minetest.sound_stop(self.sound_handle)
|
||||
self.sound_handle = nil
|
||||
end
|
||||
--self.engine:set_animation_frame_speed(0)
|
||||
|
||||
elseif self._engine_running == false and self._energy > 0 then
|
||||
self._engine_running = true
|
||||
-- sound and animation
|
||||
self.sound_handle = minetest.sound_play({name = "engine"},
|
||||
{object = self.object, gain = 2.0, pitch = 1.0, max_hear_distance = 32, loop = true,})
|
||||
--self.engine:set_animation_frame_speed(30)
|
||||
end
|
||||
end]]--
|
||||
end
|
||||
|
||||
-- steering
|
||||
if ctrl.right then
|
||||
self._steering_angle = math.max(self._steering_angle-steering_speed*dtime,-steering_limit)
|
||||
|
@ -27,8 +27,9 @@ function automobiles.ground_get_distances(self, radius, axis_distance)
|
||||
local rear_obstacle_level = automobiles.get_obstacle(rear_axis)
|
||||
|
||||
local f_x, f_z = automobiles.get_xz_from_hipotenuse(pos.x, pos.z, yaw, hip)
|
||||
--local f_y, x = automobiles.get_xz_from_hipotenuse(pos.y, pos.x, 0, hip) --the x is only a mock
|
||||
local front_axis = {x=f_x, y=pos.y, z=f_z}
|
||||
local x, f_y = automobiles.get_xz_from_hipotenuse(f_x, r_y, pitch - math.rad(90), hip) --the x is only a mock
|
||||
--minetest.chat_send_all("r: "..r_y.." f: "..f_y .." - "..math.deg(pitch))
|
||||
local front_axis = {x=f_x, y=r_y, z=f_z}
|
||||
local front_obstacle_level = automobiles.get_obstacle(front_axis)
|
||||
|
||||
--[[local left_front = {x=0, y=f_y, z=0}
|
||||
@ -48,12 +49,16 @@ function automobiles.ground_get_distances(self, radius, axis_distance)
|
||||
right_rear.x, right_rear.z = automobiles.get_xz_from_hipotenuse(r_x, r_z, yaw-math.rad(90), mid_axis)]]--
|
||||
|
||||
--lets try to get the pitch
|
||||
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 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;
|
||||
if deltaY <= self.initial_properties.stepheight then
|
||||
--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))
|
||||
end
|
||||
end
|
||||
self._pitch = pitch
|
||||
|
||||
end
|
||||
@ -70,8 +75,8 @@ function automobiles.get_obstacle(ref_pos)
|
||||
--lets clone the table
|
||||
local retval = {x=ref_pos.x, y=ref_pos.y, z=ref_pos.z}
|
||||
--minetest.chat_send_all("aa y: " .. dump(retval.y))
|
||||
local i_pos = {x=ref_pos.x, y=ref_pos.y, z=ref_pos.z}
|
||||
--minetest.chat_send_all("bb y: " .. dump(retval.y))
|
||||
local i_pos = {x=ref_pos.x, y=ref_pos.y+0.5, z=ref_pos.z}
|
||||
--minetest.chat_send_all("bb y: " .. dump(i_pos.y))
|
||||
|
||||
retval.y = automobiles.eval_interception(i_pos, {x=i_pos.x, y=i_pos.y - 2, z=i_pos.z})
|
||||
|
||||
@ -98,8 +103,7 @@ function automobiles.eval_interception(initial_pos, end_pos)
|
||||
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)
|
||||
--minetest.chat_send_all("ray intercection: " .. dump(pos.y) .. " -- " .. nodename)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
@ -5,8 +5,8 @@ roadster={}
|
||||
roadster.LONGIT_DRAG_FACTOR = 0.16*0.16
|
||||
roadster.LATER_DRAG_FACTOR = 30.0
|
||||
roadster.gravity = automobiles.gravity
|
||||
roadster.max_speed = 10
|
||||
roadster.max_acc_factor = 4
|
||||
roadster.max_speed = 15
|
||||
roadster.max_acc_factor = 5
|
||||
roadster.max_fuel = 10
|
||||
|
||||
roadster.front_wheel_xpos = 10.26
|
||||
|
@ -360,6 +360,18 @@ minetest.register_entity("automobiles_roadster:roadster", {
|
||||
player = minetest.get_player_by_name(self.driver_name)
|
||||
|
||||
if player then
|
||||
|
||||
local ctrl = player:get_player_control()
|
||||
if ctrl.aux1 then
|
||||
--sets the engine running - but sets a delay also, cause keypress
|
||||
if self._last_time_command > 0.8 then
|
||||
self._last_time_command = 0
|
||||
minetest.sound_play({name = "roadster_horn"},
|
||||
{object = self.object, gain = 0.6, pitch = 1.0, max_hear_distance = 32, loop = false,})
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local player_attach = player:get_attach()
|
||||
if player_attach then
|
||||
if self.driver_seat then
|
||||
@ -626,7 +638,7 @@ minetest.register_entity("automobiles_roadster:roadster", {
|
||||
automobiles.attach_driver(self, clicker)
|
||||
-- sound
|
||||
self.sound_handle = minetest.sound_play({name = "roadster_engine"},
|
||||
{object = self.object, gain = 0.5, pitch = 0.5, max_hear_distance = 10, loop = true,})
|
||||
{object = self.object, gain = 0.5, pitch = 0.6, max_hear_distance = 10, loop = true,})
|
||||
else
|
||||
--minetest.chat_send_all("clicou")
|
||||
--a passenger
|
||||
|
@ -38,7 +38,7 @@ end
|
||||
function roadster.engine_set_sound_and_animation(self, _longit_speed)
|
||||
--minetest.chat_send_all('test1 ' .. dump(self._engine_running) )
|
||||
if self.sound_handle then
|
||||
if (math.abs(self._longit_speed) > math.abs(_longit_speed) + 0.1) or (math.abs(self._longit_speed) + 0.1 < math.abs(_longit_speed)) then
|
||||
if (math.abs(self._longit_speed) > math.abs(_longit_speed) + 0.08) or (math.abs(self._longit_speed) + 0.08 < math.abs(_longit_speed)) then
|
||||
--minetest.chat_send_all('test2')
|
||||
roadster.engineSoundPlay(self)
|
||||
end
|
||||
@ -51,7 +51,7 @@ function roadster.engineSoundPlay(self)
|
||||
if self.object then
|
||||
self.sound_handle = minetest.sound_play({name = "roadster_engine"},
|
||||
{object = self.object, gain = 0.5,
|
||||
pitch = 0.5 + ((self._longit_speed/10)/2),
|
||||
pitch = 0.6 + ((self._longit_speed/10)/2),
|
||||
max_hear_distance = 10,
|
||||
loop = true,})
|
||||
end
|
||||
|
BIN
automobiles_roadster/sounds/roadster_horn.ogg
Normal file
BIN
automobiles_roadster/sounds/roadster_horn.ogg
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user