boat braking and fixes
parent
4abafa79a3
commit
3a9476d1d5
80
api.lua
80
api.lua
|
@ -144,6 +144,8 @@ function vehicles.object_drive(entity, dtime, def)
|
|||
local animation_speed = def.animation_speed or 20
|
||||
local uses_arrow_keys = def.uses_arrow_keys or false
|
||||
local brakes = def.brakes or false
|
||||
local handling = def.handling or {initial=1.1, braking=2.2}
|
||||
local braking_effect = def.braking_effect or "vehicles_dust.png"
|
||||
|
||||
local moving_anim = def.moving_anim
|
||||
local stand_anim = def.stand_anim
|
||||
|
@ -259,12 +261,12 @@ function vehicles.object_drive(entity, dtime, def)
|
|||
10, --minsize
|
||||
15, --maxsize
|
||||
false, --collisiondetection
|
||||
"vehicles_dust.png" --texture
|
||||
braking_effect --texture
|
||||
)
|
||||
turning_factor = 1
|
||||
turning_factor = handling.initial
|
||||
else
|
||||
timer2 = 0
|
||||
turning_factor = 1.8
|
||||
turning_factor = handling.braking
|
||||
end
|
||||
|
||||
|
||||
|
@ -308,7 +310,7 @@ function vehicles.object_drive(entity, dtime, def)
|
|||
|
||||
--apply water effects
|
||||
if is_watercraft and entity.in_water then
|
||||
entity.object:setvelocity({x=velo.x*0.9, y=velo.y+5, z=velo.z*0.9})
|
||||
entity.object:setvelocity({x=velo.x*0.9, y=velo.y+1, z=velo.z*0.9})
|
||||
elseif is_watercraft and entity.on_water == false then
|
||||
entity.object:setvelocity({x=velo.x*decell,y=velo.y-1,z=velo.z*decell})
|
||||
elseif (entity.on_water or entity.in_water) and not is_watercraft then
|
||||
|
@ -336,7 +338,7 @@ function vehicles.object_drive(entity, dtime, def)
|
|||
10, --minsize
|
||||
15, --maxsize
|
||||
false, --collisiondetection
|
||||
"vehicles_dust.png" --texture
|
||||
braking_effect --texture
|
||||
)
|
||||
if timer >= 0.5 then
|
||||
timer = timer-timer/10
|
||||
|
@ -370,7 +372,7 @@ function vehicles.object_drive(entity, dtime, def)
|
|||
|
||||
--boost
|
||||
elseif ctrl.up and not shoots2 and ctrl.aux1 and entity.boost then
|
||||
entity.object:setvelocity({x=dir.x*(speed*0.2)*math.log(timer+0.5)+8*dir.x,y=velo.y-0.5,z=dir.z*(speed*0.2)*math.log(timer+0.5)+8*dir.z})
|
||||
entity.object:setvelocity({x=dir.x*(speed*0.2)*math.log(timer+0.5)+8*dir.x,y=velo.y-gravity/2,z=dir.z*(speed*0.2)*math.log(timer+0.5)+8*dir.z})
|
||||
if boost_effect ~= nil then
|
||||
local effect_pos = {x=pos.x-dir.x*2, y=pos.y, z=pos.z-dir.z*2}
|
||||
minetest.add_particlespawner(
|
||||
|
@ -412,7 +414,7 @@ function vehicles.object_drive(entity, dtime, def)
|
|||
--move forward
|
||||
elseif ctrl.up and not fixed then
|
||||
if not fly and not is_watercraft then
|
||||
entity.object:setvelocity({x=(dir.x*(speed*0.2)*math.log(timer+0.5)+4*dir.x)/(braking*(decell+timer2/2)+1),y=velo.y-0.5,z=(dir.z*(speed*0.2)*math.log(timer+0.5)+4*dir.z)/(braking*(decell+timer2/2)+1)})
|
||||
entity.object:setvelocity({x=(dir.x*(speed*0.2)*math.log(timer+0.5)+4*dir.x)/(braking*(0.1)+1),y=velo.y-0.5,z=(dir.z*(speed*0.2)*math.log(timer+0.5)+4*dir.z)/(braking*(0.1)+1)})
|
||||
elseif not fly then
|
||||
entity.object:setvelocity({x=dir.x*(speed*0.2)*math.log(timer+0.5)+4*dir.x,y=0,z=dir.z*(speed*0.2)*math.log(timer+0.5)+4*dir.z})
|
||||
else
|
||||
|
@ -426,10 +428,66 @@ function vehicles.object_drive(entity, dtime, def)
|
|||
--move backward
|
||||
elseif ctrl.down and not fixed then
|
||||
if not is_watercraft then
|
||||
entity.object:setvelocity({x=-dir.x*(speed/4)*accell,y=velo.y-0.5,z=-dir.z*(speed/4)*accell})
|
||||
if brakes and absolute_speed > 5 then
|
||||
local velo2 = nil
|
||||
if velo2 == nil then
|
||||
velo2 = velo
|
||||
end
|
||||
local effect_pos = {x=pos.x-dir.x*2, y=pos.y, z=pos.z-dir.z*2}
|
||||
entity.object:setvelocity({x=velo2.x*(0.95), y=velo.y, z=velo2.z*(0.95)})
|
||||
minetest.add_particlespawner(
|
||||
4, --amount
|
||||
0.5, --time
|
||||
{x=effect_pos.x, y=effect_pos.y, z=effect_pos.z}, --minpos
|
||||
{x=effect_pos.x, y=effect_pos.y, z=effect_pos.z}, --maxpos
|
||||
{x=0, y=0.1, z=0}, --minvel
|
||||
{x=-velo2.x, y=0.4, z=-velo2.z}, --maxvel
|
||||
{x=-0,y=-0,z=-0}, --minacc
|
||||
{x=0,y=0,z=0}, --maxacc
|
||||
0.5, --minexptime
|
||||
1, --maxexptime
|
||||
10, --minsize
|
||||
15, --maxsize
|
||||
false, --collisiondetection
|
||||
braking_effect --texture
|
||||
)
|
||||
if timer >= 0.5 then
|
||||
timer = timer-timer/10
|
||||
end
|
||||
else
|
||||
entity.object:setvelocity({x=-dir.x*(speed/4)*accell,y=velo.y-0.5,z=-dir.z*(speed/4)*accell})
|
||||
end
|
||||
else
|
||||
if brakes and absolute_speed > 5 then
|
||||
local velo2 = nil
|
||||
if velo2 == nil then
|
||||
velo2 = velo
|
||||
end
|
||||
local effect_pos = {x=pos.x-dir.x*2, y=pos.y, z=pos.z-dir.z*2}
|
||||
entity.object:setvelocity({x=velo2.x*(0.95), y=velo.y, z=velo2.z*(0.95)})
|
||||
minetest.add_particlespawner(
|
||||
4, --amount
|
||||
0.5, --time
|
||||
{x=effect_pos.x, y=effect_pos.y, z=effect_pos.z}, --minpos
|
||||
{x=effect_pos.x, y=effect_pos.y, z=effect_pos.z}, --maxpos
|
||||
{x=0, y=0.1, z=0}, --minvel
|
||||
{x=-velo2.x, y=0.4, z=-velo2.z}, --maxvel
|
||||
{x=-0,y=-0,z=-0}, --minacc
|
||||
{x=0,y=0,z=0}, --maxacc
|
||||
0.5, --minexptime
|
||||
1, --maxexptime
|
||||
10, --minsize
|
||||
15, --maxsize
|
||||
false, --collisiondetection
|
||||
braking_effect --texture
|
||||
)
|
||||
if timer >= 0.5 then
|
||||
timer = timer-timer/10
|
||||
end
|
||||
else
|
||||
entity.object:setvelocity({x=-dir.x*(speed/4)*accell,y=0,z=-dir.z*(speed/4)*accell})
|
||||
end
|
||||
end
|
||||
--animation
|
||||
if moving_anim ~= nil and not entity.moving and not hovering then
|
||||
entity.object:set_animation(moving_anim, anim_speed, 0)
|
||||
|
@ -675,7 +733,7 @@ function vehicles.on_punch(self, puncher)
|
|||
vehicles.explodinate(self, 5)
|
||||
end
|
||||
local creative_mode = creative and creative.is_enabled_for and creative.is_enabled_for(self.driver:get_player_name())
|
||||
if self.driver == puncher and (hp == self.hp_max-1 or hp == self.hp_max or creative_mode) then
|
||||
if self.driver == puncher and (hp == self.hp_max-5 or hp == self.hp_max or creative_mode) then
|
||||
local name = self.object:get_luaentity().name
|
||||
local pos = self.object:getpos()
|
||||
minetest.env:add_item(pos, name.."_spawner")
|
||||
|
@ -712,12 +770,12 @@ function vehicles.object_no_drive(entity, dtime, def)
|
|||
local function is_water(node)
|
||||
return node == "default:river_water_source" or node == "default:water_source" or node == "default:river_water_flowing" or node == "default:water_flowing"
|
||||
end
|
||||
entity.on_water = is_water(node)
|
||||
entity.on_water = is_water(node) or is_water({x=pos.x, y=pos.y-0.6, z=pos.z})
|
||||
entity.in_water = is_water(minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name) or is_water(minetest.get_node({x=pos.x, y=pos.y+2, z=pos.z}).name)
|
||||
|
||||
--apply water effects
|
||||
if is_watercraft and entity.in_water then
|
||||
entity.object:setvelocity({x=velo.x*0.9, y=velo.y+5, z=velo.z*0.9})
|
||||
entity.object:setvelocity({x=velo.x*0.9, y=velo.y+1, z=velo.z*0.9})
|
||||
elseif is_watercraft and entity.on_water == false then
|
||||
entity.object:setvelocity({x=velo.x*decell,y=velo.y-1,z=velo.z*decell})
|
||||
elseif entity.on_water and not is_watercraft then
|
||||
|
|
12
init.lua
12
init.lua
|
@ -466,6 +466,7 @@ minetest.register_entity("vehicles:firetruck", {
|
|||
reload_time = 0.2,
|
||||
driving_sound = "engine",
|
||||
sound_duration = 11,
|
||||
handling = {initial=1.3, braking=2},
|
||||
})
|
||||
end,
|
||||
})
|
||||
|
@ -497,6 +498,7 @@ minetest.register_entity("vehicles:tractor", {
|
|||
driving_sound = "engine",
|
||||
sound_duration = 11,
|
||||
destroy_node = "farming:wheat_8",
|
||||
handling = {initial=1.3, braking=2},
|
||||
})
|
||||
end,
|
||||
})
|
||||
|
@ -613,6 +615,7 @@ minetest.register_entity("vehicles:ambulance", {
|
|||
stand_anim = {x=1, y=1},
|
||||
driving_sound = "engine",
|
||||
sound_duration = 11,
|
||||
handling = {initial=1.3, braking=2},
|
||||
brakes = true,
|
||||
},
|
||||
function()
|
||||
|
@ -1533,7 +1536,7 @@ minetest.register_entity("vehicles:boat", {
|
|||
textures = {"vehicles_boat.png"},
|
||||
velocity = 15,
|
||||
acceleration = -5,
|
||||
stepheight = 1,
|
||||
stepheight = 0,
|
||||
hp_max = 200,
|
||||
physical = true,
|
||||
collisionbox = {-1, 0.2, -1, 1.3, 1, 1},
|
||||
|
@ -1551,6 +1554,12 @@ minetest.register_entity("vehicles:boat", {
|
|||
decell = 0.85,
|
||||
is_watercraft = true,
|
||||
gravity = 0,
|
||||
boost = true,
|
||||
boost_duration = 10,
|
||||
boost_effect = "vehicles_splash.png",
|
||||
brakes = true,
|
||||
braking_effect = "vehicles_splash.png",
|
||||
handling = {initial=1.8, braking=2.3}
|
||||
})
|
||||
end,
|
||||
})
|
||||
|
@ -1590,6 +1599,7 @@ minetest.register_entity("vehicles:jet", {
|
|||
stand_anim = {x=1, y=1},
|
||||
fly = true,
|
||||
fly_mode = "rise",
|
||||
braking_effect = "vehicles_trans.png",
|
||||
})
|
||||
end,
|
||||
})
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 424 B |
Loading…
Reference in New Issue