forked from VoxeLibre/VoxeLibre
Add in prototype swimming
This commit is contained in:
parent
f1141aed9f
commit
dda7839d8c
|
@ -2,6 +2,7 @@ local math_random = math.random
|
||||||
|
|
||||||
local vector_multiply = vector.multiply
|
local vector_multiply = vector.multiply
|
||||||
local vector_add = vector.add
|
local vector_add = vector.add
|
||||||
|
local vector_new = vector.new
|
||||||
|
|
||||||
local minetest_yaw_to_dir = minetest.yaw_to_dir
|
local minetest_yaw_to_dir = minetest.yaw_to_dir
|
||||||
local minetest_get_item_group = minetest.get_item_group
|
local minetest_get_item_group = minetest.get_item_group
|
||||||
|
@ -201,11 +202,32 @@ local flop = function(self,dtime)
|
||||||
mobs.flop(self)
|
mobs.flop(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--this is to swap the built in engine acceleration modifier
|
||||||
|
local fly_physics_swapper = function(self,inside_fly_node)
|
||||||
|
|
||||||
|
--push non-existing physics switch to new mobs
|
||||||
|
self.fly_physics_switch = self.fly_physics_switch or not inside_fly_node
|
||||||
|
|
||||||
|
--should be flying, gravity is applied, switch to floating
|
||||||
|
if inside_fly_node and not self.fly_physics_switch then
|
||||||
|
self.object:set_acceleration(vector_new(0,0,0))
|
||||||
|
self.fly_physics_switch = true
|
||||||
|
--not be flying, gravity isn't applied, switch to falling
|
||||||
|
elseif not inside_fly_node and self.fly_physics_switch then
|
||||||
|
self.pitch = 0
|
||||||
|
self.object:set_acceleration(vector_new(0,-self.gravity,0))
|
||||||
|
self.fly_physics_switch = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local random_pitch_multiplier = {-1,1}
|
||||||
-- states are executed here
|
-- states are executed here
|
||||||
local fly_state_execution = function(self,dtime)
|
local fly_state_execution = function(self,dtime)
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
|
|
||||||
|
pos.y = pos.y + self.object:get_properties().collisionbox[5]
|
||||||
local current_node = minetest_get_node(pos).name
|
local current_node = minetest_get_node(pos).name
|
||||||
local inside_fly_node = false
|
local inside_fly_node = false
|
||||||
|
|
||||||
|
@ -217,10 +239,12 @@ local fly_state_execution = function(self,dtime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--turn gravity on or off
|
||||||
|
fly_physics_swapper(self,inside_fly_node)
|
||||||
|
|
||||||
--fly properly if inside fly node
|
--fly properly if inside fly node
|
||||||
if inside_fly_node then
|
if inside_fly_node then
|
||||||
|
|
||||||
if self.state == "stand" then
|
if self.state == "stand" then
|
||||||
|
|
||||||
--do animation
|
--do animation
|
||||||
|
@ -231,11 +255,27 @@ local fly_state_execution = function(self,dtime)
|
||||||
|
|
||||||
--print("standing")
|
--print("standing")
|
||||||
|
|
||||||
|
mobs.set_fly_velocity(self,0)
|
||||||
|
|
||||||
elseif self.state == "fly" then
|
elseif self.state == "fly" then
|
||||||
|
|
||||||
|
self.walk_timer = self.walk_timer - dtime
|
||||||
|
|
||||||
--print("flying")
|
--reset the walk timer
|
||||||
|
if self.walk_timer <= 0 then
|
||||||
|
|
||||||
|
--re-randomize the walk timer
|
||||||
|
self.walk_timer = math.random(1,6) + math.random()
|
||||||
|
|
||||||
|
--set the mob into a random direction
|
||||||
|
self.yaw = (math_random() * (math.pi * 2))
|
||||||
|
|
||||||
|
--create a truly random pitch, since there is no easy access to pitch math that I can find
|
||||||
|
self.pitch = math_random() * random_pitch_multiplier[math_random(1,2)]
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
mobs.set_fly_velocity(self,self.walk_velocity)
|
||||||
end
|
end
|
||||||
--flop around if not inside fly node
|
--flop around if not inside fly node
|
||||||
else
|
else
|
||||||
|
|
|
@ -98,4 +98,36 @@ mobs.flop = function(self, velocity)
|
||||||
self.object:add_velocity(final_additional_force)
|
self.object:add_velocity(final_additional_force)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- move mob in facing direction
|
||||||
|
--this has been modified to be internal
|
||||||
|
--internal = lua (self.yaw)
|
||||||
|
--engine = c++ (self.object:get_yaw())
|
||||||
|
mobs.set_fly_velocity = function(self, v)
|
||||||
|
|
||||||
|
local yaw = (self.yaw or 0)
|
||||||
|
local pitch = (self.pitch or 0)
|
||||||
|
|
||||||
|
local current_velocity = self.object:get_velocity()
|
||||||
|
|
||||||
|
local goal_velocity = {
|
||||||
|
x = (math_sin(yaw) * -v),
|
||||||
|
y = pitch,
|
||||||
|
z = (math_cos(yaw) * v),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
local new_velocity_addition = vector.subtract(goal_velocity,current_velocity)
|
||||||
|
|
||||||
|
if vector_length(new_velocity_addition) > vector_length(goal_velocity) then
|
||||||
|
vector.multiply(new_velocity_addition, (vector_length(goal_velocity) / vector_length(new_velocity_addition)))
|
||||||
|
end
|
||||||
|
|
||||||
|
--smooths out mobs a bit
|
||||||
|
if vector_length(new_velocity_addition) >= 0.0001 then
|
||||||
|
self.object:add_velocity(new_velocity_addition)
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -16,6 +16,7 @@ mobs:register_mob("mobs_mc:squid", {
|
||||||
xp_min = 1,
|
xp_min = 1,
|
||||||
xp_max = 3,
|
xp_max = 3,
|
||||||
armor = 100,
|
armor = 100,
|
||||||
|
rotate = 270,
|
||||||
-- FIXME: If the squid is near the floor, it turns black
|
-- FIXME: If the squid is near the floor, it turns black
|
||||||
collisionbox = {-0.4, 0.0, -0.4, 0.4, 0.9, 0.4},
|
collisionbox = {-0.4, 0.0, -0.4, 0.4, 0.9, 0.4},
|
||||||
visual = "mesh",
|
visual = "mesh",
|
||||||
|
|
Loading…
Reference in New Issue