diff --git a/src/snowball.lua b/src/snowball.lua index 0a2fcdc..992e9d5 100644 --- a/src/snowball.lua +++ b/src/snowball.lua @@ -129,7 +129,7 @@ end --Snowball_entity.on_step()--> called when snowball is moving. function snow_snowball_ENTITY.on_step(self, dtime) - self.timer = self.timer+dtime + self.timer = self.timer + dtime if self.timer > 600 then -- 10 minutes are too long for a snowball to fly somewhere self.object:remove() @@ -137,14 +137,32 @@ function snow_snowball_ENTITY.on_step(self, dtime) end if self.physical then - local fell = self.object:getvelocity().y == 0 + local vel = self.object:getvelocity() + local fell = vel.y == 0 if not fell then + if self.probably_stuck then + self.probably_stuck = nil + end + return + end + if self.probably_stuck + and vel.x == 0 + and vel.z == 0 then + -- add a small velocity to move it from the corner + vel.x = math.random() - 0.5 + vel.z = math.random() - 0.5 + self.object:set_velocity(vel) + self.probably_stuck = nil return end local pos = vector.round(self.object:getpos()) if minetest.get_node(pos).name == "air" then pos.y = pos.y-1 if minetest.get_node(pos).name == "air" then + if vel.x == 0 + and vel.z == 0 then + self.probably_stuck = true + end return end end