make boats float

This commit is contained in:
oilboi 2020-02-19 03:46:24 -05:00
parent 45d06cbfc7
commit f8c7227589
3 changed files with 61 additions and 5 deletions

View File

@ -12,8 +12,7 @@ minetest.register_entity("boat:boat", {
is_visible = true,
},
driver = "",
rider = "",
get_staticdata = function(self)
@ -37,7 +36,63 @@ minetest.register_entity("boat:boat", {
end,
on_step = function(self, dtime)
--players push boat
push = function(self)
local pos = self.object:getpos()
for _,object in ipairs(minetest.get_objects_inside_radius(pos, 1)) do
if object:is_player() and object:get_player_name() ~= self.rider then
local player_pos = object:getpos()
pos.y = 0
player_pos.y = 0
local currentvel = self.object:getvelocity()
local vel = vector.subtract(pos, player_pos)
vel = vector.normalize(vel)
local distance = vector.distance(pos,player_pos)
distance = (1-distance)*10
vel = vector.multiply(vel,distance)
local acceleration = vector.new(vel.x-currentvel.x,0,vel.z-currentvel.z)
self.object:add_velocity(acceleration)
end
end
end,
--makes the boat float
float = function(self)
local pos = self.object:getpos()
local node = minetest.get_node(pos).name
local vel = self.object:getvelocity()
local goal = 1
local acceleration = vector.new(0,goal-vel.y,0)
self.swimming = false
if node == "main:water" or node =="main:waterflow" then
print("float man")
self.swimming = true
self.object:add_velocity(acceleration)
end
end,
--slows the boat down
slowdown = function(self)
local vel = self.object:getvelocity()
local deceleration = vector.multiply(vel, -0.01)
self.object:add_velocity(deceleration)
end,
on_step = function(self, dtime)
self.push(self)
self.float(self)
self.slowdown(self)
end,
})

View File

@ -158,7 +158,7 @@ minetest.register_entity("mob:pig", {
local acceleration = vector.new(0,goal-vel.y,0)
self.swimming = false
if node == ("main:water" or "main:water_flow") then
if node == ("main:water" or "main:waterflow") then
self.swimming = true
self.object:add_velocity(acceleration)
end

View File

@ -23,6 +23,7 @@
--ladders - only placeable on walls
--eating animation - particles? - entity?
boats
redstone - make nodes drop multiple items individually
crafting bench
fishing
bows