SussyCraft/mods/amogus_entities/entities/amogus_entity.lua

57 lines
1.8 KiB
Lua
Raw Normal View History

2023-01-08 00:11:47 +01:00
local entity = {
physical = true,
collisionbox = {-0.5, 0, -0.5, 0.5, 1, 0.5},
visual = "mesh",
visual_size = {x=10, y=10, z=10},
mesh = "amogus_entity.obj",
textures = {"amogus_entity.png"},
on_rightclick = function(self, clicker)
minetest.chat_send_player(clicker:get_player_name(), "AMOGUS")
end,
is_going_forward = true,
gravity = 9.81/60,
speed = 0.1,
on_step = function(self, dtime)
-- Switch "is_going_forward" 1% chance randomly between true and false
if math.random(200) == 1 then
self.is_going_forward = not self.is_going_forward
end
-- Go forward if "is_going_forward" is true
if self.is_going_forward then
local pos = self.object:get_pos()
local dir = self.object:get_yaw()
pos.x = pos.x + math.cos(dir) * self.speed
pos.z = pos.z + math.sin(dir) * self.speed
self.object:set_pos(pos)
end
-- some chance of turning left or right
if math.random(50) == 1 then
self.object:set_yaw(self.object:get_yaw() + math.pi/2)
elseif math.random(50) == 1 then
self.object:set_yaw(self.object:get_yaw() - math.pi/2)
end
-- Make it also jump when running into some block
local pos = self.object:get_pos()
local bnode = minetest.get_node(pos)
if bnode.name ~= "air" then
local vel = self.object:get_velocity()
vel.y = vel.y + 5
self.object:set_velocity(vel)
end
-- change velocity by gravity
local vel = self.object:get_velocity()
vel.y = vel.y - self.gravity
self.object:set_velocity(vel)
end
}
minetest.register_entity("amogus_entities:amogus", entity)