SussyCraft/mods/amogus_entities/entities/amogus_entity.lua
2023-01-08 02:32:49 +01:00

133 lines
3.8 KiB
Lua

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(), "WHY ARE YOU SUCH SUSSY BAKA?")
end,
-- physics config -- <--- HERE IS PART FOR YOU "USER" (NERD)
gravity = 9.81, -- m/s^2
walk_acceletation_speed = 0.2, -- self explainatory
jump_force = 20, -- self explainatory
friction = 0.5, -- friction (0.0 - no friction like perfectly smooth ice | 1.0 - full friction and can't even move)
rotation_friction = 0.5, -- the same but for rotation
bounciness = 0.5, -- bounciness (0.0 - no bounce at all | 1.0 - full bounce and bouces infinitely back to the same height)
--------------------
is_going_forward = true,
block_lastly_in_front = false,
direction_velocity = 0,
on_activate = function(self, staticdata)
local direction = math.random() * 2 * math.pi
-- procesing config values --
--friction = 1 - self.friction
--rotation_friction = 1 - self.rotation_friction
bounciness = 1 - self.bounciness
-----------------------------
-- kill itself (debugging)
--self.object:remove()
end,
on_step = function(self, dtime)
-- play amogus sound randomly
if math.random(500) == 1 then
minetest.sound_play("amogus_sound", {
pos = self.object:get_pos(),
gain = 1.0,
max_hear_distance = 5
})
end
-- random changing between walking and standing still
if math.random(200) == 1 then
self.is_going_forward = not self.is_going_forward
end
-- perform calculations on direction
local dir = self.object:get_yaw()
local dir_cos = math.cos(dir)
local dir_sin = math.sin(dir)
-- Go forward if "is_going_forward" is true
if self.is_going_forward then
--local pos = self.object:get_pos()
local vel = self.object:get_velocity()
vel.x = vel.x + dir_cos * self.walk_acceletation_speed
vel.z = vel.z + dir_sin * self.walk_acceletation_speed
self.object:set_velocity(vel)
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
-- print curent amogus entity y position
--minetest.chat_send_player("singleplayer", "Y: " .. pos.y)
-- print delta time
minetest.chat_send_player("singleplayer", "dtime: " .. dtime)
-- Make it also jump when some block is in front of it
local pos = self.object:get_pos()
pos.x = pos.x + dir_cos
pos.z = pos.z + dir_sin
local bnode = minetest.get_node(pos)
if bnode.name ~= "air" then
if self.block_lastly_in_front == false then
self.block_lastly_in_front = true
local vel = self.object:get_velocity()
vel.y = vel.y + self.jump_force
self.object:set_velocity(vel)
end
else
self.block_lastly_in_front = false
end
local vel = self.object:get_velocity()
-- change velocity by gravity
vel.y = vel.y - self.gravity * dtime * 2
-- change velocity by friction
vel.x = vel.x * (1 - self.friction * dtime)
vel.z = vel.z * (1 - self.friction * dtime)
self.object:set_velocity(vel)
end
}
minetest.register_entity("amogus_entities:amogus", entity)