mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2025-01-09 16:49:35 +01:00
Fix bobber colliding with doors,trapdoors, rework vl_projectile collides_with handling to affect all entities physical or not
This commit is contained in:
parent
0385abc277
commit
70d05a6720
2 changed files with 21 additions and 20 deletions
|
@ -313,11 +313,12 @@ bobber_ENTITY.on_step = bobber_on_step
|
|||
core.register_entity("mcl_fishing:bobber_entity", bobber_ENTITY)
|
||||
|
||||
vl_projectile.register("mcl_fishing:flying_bobber_entity", {
|
||||
physical = false,
|
||||
physical = true,
|
||||
collide_with_objects = false,
|
||||
timer=0,
|
||||
textures = {"mcl_fishing_bobber.png"}, --FIXME: Replace with correct texture.
|
||||
visual_size = {x=0.5, y=0.5},
|
||||
collisionbox = {0,0,0,0,0,0},
|
||||
collisionbox = {-0.1,-0.1,-0.1,0.1,0.1,0.1},
|
||||
pointable = false,
|
||||
|
||||
get_staticdata = mcl_throwing.get_staticdata,
|
||||
|
|
|
@ -359,24 +359,24 @@ function mod.collides_with_solids(self, dtime, entity_def, projectile_def)
|
|||
local node_def = core.registered_nodes[node.name]
|
||||
local collides_with = projectile_def.collides_with
|
||||
|
||||
if entity_def.physical then
|
||||
-- Projectile has stopped in one axis, so it probably hit something.
|
||||
-- This detection is a bit clunky, but sadly, MT does not offer a direct collision detection for us. :-(
|
||||
local vel = self.object:get_velocity()
|
||||
if not self._last_velocity then
|
||||
self._last_velocity = vel
|
||||
return
|
||||
end
|
||||
if not collides_with or not mcl_util.match_node_to_filter(node.name, collides_with) then
|
||||
if entity_def.physical then
|
||||
-- Projectile has stopped in one axis, so it probably hit something.
|
||||
-- This detection is a bit clunky, but sadly, MT does not offer a direct collision detection for us. :-(
|
||||
local vel = self.object:get_velocity()
|
||||
if not self._last_velocity then
|
||||
self._last_velocity = vel
|
||||
return
|
||||
end
|
||||
|
||||
local delta_v = (vel - self._last_velocity)
|
||||
local vel_length = vector.length(vel)
|
||||
if vel_length > 1 then delta_v = delta_v / vel_length end
|
||||
self._last_velocity = vel
|
||||
if math.abs(delta_v.x) <= 0.1 and math.abs(delta_v.z) <= 0.1 and math.abs(delta_v.y) <= 0.2 then
|
||||
return
|
||||
end
|
||||
else
|
||||
if node_def and not node_def.walkable and (not collides_with or not mcl_util.match_node_to_filter(node.name, collides_with)) then
|
||||
local delta_v = (vel - self._last_velocity)
|
||||
local vel_length = vector.length(vel)
|
||||
if vel_length > 1 then delta_v = delta_v / vel_length end
|
||||
self._last_velocity = vel
|
||||
if math.abs(delta_v.x) <= 0.1 and math.abs(delta_v.z) <= 0.1 and math.abs(delta_v.y) <= 0.2 then
|
||||
return
|
||||
end
|
||||
elseif node_def and not node_def.walkable then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
@ -430,7 +430,7 @@ function mod.collides_with_solids(self, dtime, entity_def, projectile_def)
|
|||
if hook then hook(self, self._stuckin, snode, sdef) end
|
||||
end
|
||||
|
||||
-- Call entity collied hook
|
||||
-- Call entity collided hook
|
||||
local hook = projectile_def.on_collide_with_solid
|
||||
if hook then hook(self, pos, node, node_def) end
|
||||
|
||||
|
|
Loading…
Reference in a new issue