SussyCraft/mods/amogus_entities/entities/amogus_entity.lua

133 lines
3.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)
2023-01-08 02:32:49 +01:00
minetest.chat_send_player(clicker:get_player_name(), "WHY ARE YOU SUCH SUSSY BAKA?")
2023-01-08 00:11:47 +01:00
end,
2023-01-08 02:32:49 +01:00
-- 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)
--------------------
2023-01-08 00:11:47 +01:00
is_going_forward = true,
2023-01-08 02:32:49 +01:00
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,
2023-01-08 00:11:47 +01:00
on_step = function(self, dtime)
2023-01-08 02:32:49 +01:00
-- 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
2023-01-08 00:11:47 +01:00
if math.random(200) == 1 then
self.is_going_forward = not self.is_going_forward
end
2023-01-08 02:32:49 +01:00
-- perform calculations on direction
local dir = self.object:get_yaw()
local dir_cos = math.cos(dir)
local dir_sin = math.sin(dir)
2023-01-08 00:11:47 +01:00
-- Go forward if "is_going_forward" is true
if self.is_going_forward then
2023-01-08 02:32:49 +01:00
--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)
2023-01-08 00:11:47 +01:00
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
2023-01-08 02:32:49 +01:00
-- 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
2023-01-08 00:11:47 +01:00
local pos = self.object:get_pos()
2023-01-08 02:32:49 +01:00
pos.x = pos.x + dir_cos
pos.z = pos.z + dir_sin
2023-01-08 00:11:47 +01:00
local bnode = minetest.get_node(pos)
if bnode.name ~= "air" then
2023-01-08 02:32:49 +01:00
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
2023-01-08 00:11:47 +01:00
end
2023-01-08 02:32:49 +01:00
2023-01-08 00:11:47 +01:00
local vel = self.object:get_velocity()
2023-01-08 02:32:49 +01:00
-- 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)
2023-01-08 00:11:47 +01:00
self.object:set_velocity(vel)
end
}
minetest.register_entity("amogus_entities:amogus", entity)