Fix collision detection for jumping
This commit is contained in:
parent
e6ff7a1b70
commit
c8757c94a0
52
entity.lua
52
entity.lua
@ -51,6 +51,8 @@ local function random_turn(self)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local walk_speed = 1.5
|
||||||
|
|
||||||
local def = {
|
local def = {
|
||||||
hp_max = 20,
|
hp_max = 20,
|
||||||
physical = true,
|
physical = true,
|
||||||
@ -67,7 +69,7 @@ local def = {
|
|||||||
walk_START = 168,
|
walk_START = 168,
|
||||||
walk_END = 187
|
walk_END = 187
|
||||||
},
|
},
|
||||||
walk_speed = 1.5,
|
walk_speed = walk_speed,
|
||||||
jump_height = 5,
|
jump_height = 5,
|
||||||
animation_speed = 30,
|
animation_speed = 30,
|
||||||
knockback_level = 2
|
knockback_level = 2
|
||||||
@ -135,7 +137,36 @@ local function explode(self, pos)
|
|||||||
core.sound_play("sneeker_explode", {object=self.object, gain=sneeker.boom_gain, max_hear_distance=2*64})
|
core.sound_play("sneeker_explode", {object=self.object, gain=sneeker.boom_gain, max_hear_distance=2*64})
|
||||||
end
|
end
|
||||||
|
|
||||||
def.on_step = function(self, dtime)
|
local function h_collides(pos, collision_info, touching_ground)
|
||||||
|
if not touching_ground or type(collision_info) ~= "table" or #collision_info == 0 then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local pos_y = math.floor(pos.y)
|
||||||
|
local h_col
|
||||||
|
|
||||||
|
for _, col in ipairs(collision_info) do
|
||||||
|
local npos = col.node_pos
|
||||||
|
if npos and col.type == "node" then
|
||||||
|
-- exclude ground collisions
|
||||||
|
if math.floor(npos.y) > pos_y then
|
||||||
|
h_col = col
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not h_col then return false end
|
||||||
|
|
||||||
|
local h_vel = {
|
||||||
|
x = math.floor(h_col.new_velocity.x * 10) / 10,
|
||||||
|
z = math.floor(h_col.new_velocity.z * 10) / 10,
|
||||||
|
}
|
||||||
|
|
||||||
|
return h_vel.x < walk_speed and h_vel.z < walk_speed, h_col.node_pos
|
||||||
|
end
|
||||||
|
|
||||||
|
def.on_step = function(self, dtime, moveresult)
|
||||||
-- update lifetime timer
|
-- update lifetime timer
|
||||||
-- FIXME: this is longer than realtime
|
-- FIXME: this is longer than realtime
|
||||||
self.lifetimer = self.lifetimer + dtime
|
self.lifetimer = self.lifetimer + dtime
|
||||||
@ -180,6 +211,13 @@ def.on_step = function(self, dtime)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if self.chase or self.state == "chase" or self.state == "walk" then
|
||||||
|
local collided, npos = h_collides(pos, moveresult.collisions, moveresult.touching_ground)
|
||||||
|
if collided then
|
||||||
|
jump(self, npos, self.direction)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local yaw = self.object:get_yaw()
|
local yaw = self.object:get_yaw()
|
||||||
local inside = core.get_objects_inside_radius(pos, 10)
|
local inside = core.get_objects_inside_radius(pos, 10)
|
||||||
local walk_speed = self.walk_speed
|
local walk_speed = self.walk_speed
|
||||||
@ -262,11 +300,6 @@ def.on_step = function(self, dtime)
|
|||||||
self.turn_speed = 0.05*math.random()
|
self.turn_speed = 0.05*math.random()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Jump
|
|
||||||
if self.jump_timer > 0.2 then
|
|
||||||
jump(self, pos, self.direction)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.state == "chase" then
|
if self.state == "chase" then
|
||||||
@ -333,11 +366,6 @@ def.on_step = function(self, dtime)
|
|||||||
if can_set then
|
if can_set then
|
||||||
self.object:set_velocity({x=direction.x*2.5, y=velocity.y, z=direction.z*2.5})
|
self.object:set_velocity({x=direction.x*2.5, y=velocity.y, z=direction.z*2.5})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Jump
|
|
||||||
if self.jump_timer > 0.2 then
|
|
||||||
jump(self, pos, direction)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user