mirror of
https://github.com/APercy/automobiles_pck
synced 2025-09-21 10:46:23 +02:00
sound
This commit is contained in:
parent
e4198dd88c
commit
b1b698fc66
@ -46,9 +46,9 @@ function automobiles.ground_get_distances(self, radius, axis_length, axis_distan
|
||||
--lets try to get the pitch
|
||||
local deltaX = axis_distance;
|
||||
local deltaY = pos.y - front_obstacle_level.y;
|
||||
minetest.chat_send_all("deutaY "..deltaY)
|
||||
--minetest.chat_send_all("deutaY "..deltaY)
|
||||
pitch = math.atan2(deltaY, deltaX);
|
||||
minetest.chat_send_all(" pitch ".. math.deg(pitch).." -- r: "..pos.y.." -- f: "..front_obstacle_level.y)
|
||||
--minetest.chat_send_all(" pitch ".. math.deg(pitch).." -- r: "..pos.y.." -- f: "..front_obstacle_level.y)
|
||||
self._pitch = pitch
|
||||
|
||||
end
|
||||
@ -64,15 +64,15 @@ end
|
||||
function automobiles.get_obstacle(ref_pos, y_max)
|
||||
--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))
|
||||
--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))
|
||||
--minetest.chat_send_all("bb y: " .. dump(retval.y))
|
||||
|
||||
local e_pos = {x=ref_pos.x, y=ref_pos.y, z=ref_pos.z}
|
||||
e_pos.y = e_pos.y - y_max
|
||||
|
||||
--//upper position
|
||||
minetest.chat_send_all("ref y: " .. dump(ref_pos.y) .. " ret Y: ".. dump(retval.y))
|
||||
--minetest.chat_send_all("ref y: " .. dump(ref_pos.y) .. " ret Y: ".. dump(retval.y))
|
||||
local cast = minetest.raycast(i_pos, e_pos, true, false)
|
||||
local thing = cast:next()
|
||||
while thing do
|
||||
@ -82,7 +82,7 @@ function automobiles.get_obstacle(ref_pos, y_max)
|
||||
retval.y = e_pos.y - 1
|
||||
--minetest.chat_send_all("ray intercection: " .. dump(pos.y))
|
||||
local node_name = minetest.get_node(thing.under).name
|
||||
minetest.chat_send_all("ray intercection: " .. dump(pos.y) .. " -- " .. node_name)
|
||||
--minetest.chat_send_all("ray intercection: " .. dump(pos.y) .. " -- " .. node_name)
|
||||
break
|
||||
end
|
||||
end
|
||||
@ -98,7 +98,7 @@ function automobiles.get_obstacle(ref_pos, y_max)
|
||||
if pos then
|
||||
retval.y = retval.y - 4
|
||||
local node_name = minetest.get_node(thing.under).name
|
||||
minetest.chat_send_all("ray 2 intercection: " .. dump(pos.y) .. " -- " .. node_name)
|
||||
--minetest.chat_send_all("ray 2 intercection: " .. dump(pos.y) .. " -- " .. node_name)
|
||||
break
|
||||
end
|
||||
end
|
||||
@ -118,7 +118,7 @@ function automobiles.get_obstacle(ref_pos, y_max)
|
||||
if pos then
|
||||
--retval = pos
|
||||
local node_name = minetest.get_node(thing.under).name
|
||||
minetest.chat_send_all("ray 3 intercection: " .. dump(pos.y) .. " -- " .. node_name)
|
||||
--minetest.chat_send_all("ray 3 intercection: " .. dump(pos.y) .. " -- " .. node_name)
|
||||
end
|
||||
end
|
||||
thing = cast:next()
|
||||
@ -135,7 +135,7 @@ function automobiles.get_obstacle(ref_pos, y_max)
|
||||
if pos then
|
||||
--retval = pos
|
||||
local node_name = minetest.get_node(thing.under).name
|
||||
minetest.chat_send_all("ray 4 intercection: " .. dump(pos.y) .. " -- " .. node_name)
|
||||
--minetest.chat_send_all("ray 4 intercection: " .. dump(pos.y) .. " -- " .. node_name)
|
||||
end
|
||||
end
|
||||
thing = cast:next()
|
||||
|
@ -163,7 +163,7 @@ minetest.register_entity("automobiles_roadster:roadster", {
|
||||
initial_properties = {
|
||||
physical = true,
|
||||
collide_with_objects = true,
|
||||
collisionbox = {-1.1, -0.5, -1.1, 1.1, 2, 1.1},
|
||||
collisionbox = {-0.5, -0.5, -0.5, 0.5, 2, 0.5},
|
||||
selectionbox = {-1.5, 0.0, -1.5, 1.5, 2, 1.5},
|
||||
stepheight = 0.5,
|
||||
visual = "mesh",
|
||||
@ -214,6 +214,7 @@ minetest.register_entity("automobiles_roadster:roadster", {
|
||||
_last_time_command = 0,
|
||||
_roll = math.rad(0),
|
||||
_pitch = math.rad(90),
|
||||
_longit_speed = 0,
|
||||
|
||||
get_staticdata = function(self) -- unloaded/unloads ... is now saved
|
||||
return minetest.serialize({
|
||||
@ -414,13 +415,13 @@ minetest.register_entity("automobiles_roadster:roadster", {
|
||||
self._steering_angle / 30 * turn_rate * automobiles.sign(longit_speed)
|
||||
end
|
||||
|
||||
--automobiles.ground_get_distances(self, 0.5, 20.52, 24.22)
|
||||
automobiles.ground_get_distances(self, 0.5, 20.52, 24.22)
|
||||
|
||||
--[[if player and is_attached then
|
||||
player:set_look_horizontal(newyaw)
|
||||
end]]--
|
||||
|
||||
local newpitch = velocity.y * math.rad(6)
|
||||
local newpitch = self._pitch --velocity.y * math.rad(6)
|
||||
|
||||
--[[
|
||||
accell correction
|
||||
@ -448,9 +449,11 @@ minetest.register_entity("automobiles_roadster:roadster", {
|
||||
end
|
||||
|
||||
if newyaw~=yaw or newpitch~=pitch then self.object:set_rotation({x=newpitch,y=newyaw,z=0}) end
|
||||
roadster.engine_set_sound_and_animation(self, longit_speed)
|
||||
|
||||
--saves last velocity for collision detection (abrupt stop)
|
||||
self.lastvelocity = self.object:get_velocity()
|
||||
self._longit_speed = longit_speed
|
||||
|
||||
-- calculate energy consumption --
|
||||
----------------------------------
|
||||
@ -583,6 +586,11 @@ minetest.register_entity("automobiles_roadster:roadster", {
|
||||
if name == self.driver_name then
|
||||
--detach all
|
||||
automobiles.dettach_driver(self, clicker)
|
||||
-- sound
|
||||
if self.sound_handle then
|
||||
minetest.sound_stop(self.sound_handle)
|
||||
self.sound_handle = nil
|
||||
end
|
||||
|
||||
local passenger = nil
|
||||
if self._passenger then
|
||||
@ -596,6 +604,9 @@ minetest.register_entity("automobiles_roadster:roadster", {
|
||||
if name == self.owner then
|
||||
--is the owner, okay, lets attach
|
||||
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,})
|
||||
else
|
||||
--minetest.chat_send_all("clicou")
|
||||
--a passenger
|
||||
|
@ -34,3 +34,25 @@ function roadster.destroy(self, puncher)
|
||||
|
||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_roadster:roadster')
|
||||
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
|
||||
--minetest.chat_send_all('test2')
|
||||
roadster.engineSoundPlay(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function roadster.engineSoundPlay(self)
|
||||
--sound
|
||||
if self.sound_handle then minetest.sound_stop(self.sound_handle) end
|
||||
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),
|
||||
max_hear_distance = 10,
|
||||
loop = true,})
|
||||
end
|
||||
end
|
||||
|
BIN
automobiles_roadster/sounds/roadster_engine.ogg
Normal file
BIN
automobiles_roadster/sounds/roadster_engine.ogg
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user