2023-01-22 20:51:24 +01:00
|
|
|
-- create a random number from 0 to 3
|
|
|
|
|
|
|
|
|
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",
|
2023-01-22 20:51:24 +01:00
|
|
|
textures = {"amogus_entity.png",},
|
2023-01-08 00:11:47 +01:00
|
|
|
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
|
2023-01-08 15:25:36 +01:00
|
|
|
rotation_acceletation_speed = 3, -- self explainatory
|
2023-01-08 02:32:49 +01:00
|
|
|
|
2023-01-08 15:25:36 +01:00
|
|
|
min_jump_force = 15, -- self explainatory
|
|
|
|
max_jump_force = 25, -- self explainatory
|
|
|
|
|
|
|
|
friction = 0.6, -- friction (0.0 - no friction like perfectly smooth ice | 1.0 - full friction and can't even move)
|
|
|
|
rotation_friction = 0.75, -- the same but for rotation
|
|
|
|
bounciness = 0.8, -- bounciness (0.0 - no bounce at all | 1.0 - full bounce and bouces infinitely back to the same height)
|
2023-01-08 02:32:49 +01:00
|
|
|
--------------------
|
|
|
|
|
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,
|
2023-01-08 15:25:36 +01:00
|
|
|
rotation_velocity = 0,
|
|
|
|
rotation_direction = nil,
|
|
|
|
last_y_velocity = 0,
|
2023-01-08 02:32:49 +01:00
|
|
|
|
|
|
|
on_activate = function(self, staticdata)
|
2023-01-08 15:25:36 +01:00
|
|
|
self.object:set_yaw(math.random() * 2 * math.pi)
|
|
|
|
self.rotation_direction = math.random(-1, 1)
|
|
|
|
self.min_max_jump_force_diff = self.max_jump_force - self.min_jump_force
|
2023-01-08 02:32:49 +01:00
|
|
|
|
|
|
|
-- 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
|
2023-01-08 15:25:36 +01:00
|
|
|
if math.random(300) == 1 then
|
2023-01-08 02:32:49 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2023-01-08 15:25:36 +01:00
|
|
|
-- some chance of chaning rotation_direction to random value
|
|
|
|
if math.random(10) == 1 then
|
|
|
|
--self.rotation_direction = math.random(-1, 1)
|
|
|
|
local rand = math.random()
|
2023-01-08 02:32:49 +01:00
|
|
|
|
2023-01-08 15:25:36 +01:00
|
|
|
if rand < 0.2 then
|
|
|
|
self.rotation_direction = 1
|
|
|
|
elseif rand < 0.4 then
|
|
|
|
self.rotation_direction = -1
|
|
|
|
else
|
|
|
|
self.rotation_direction = 0
|
|
|
|
end
|
2023-01-08 02:32:49 +01:00
|
|
|
|
2023-01-08 15:25:36 +01:00
|
|
|
end
|
2023-01-08 02:32:49 +01:00
|
|
|
|
2023-01-08 15:25:36 +01:00
|
|
|
-- update rotation_velocity
|
|
|
|
self.rotation_velocity = self.rotation_velocity + self.rotation_direction * self.rotation_acceletation_speed * dtime
|
|
|
|
|
|
|
|
-- update rotation
|
|
|
|
self.object:set_yaw(self.object:get_yaw() + self.rotation_velocity * dtime)
|
|
|
|
|
|
|
|
-- apply rotation_friction
|
|
|
|
self.rotation_velocity = self.rotation_velocity * (1 - self.rotation_friction * dtime)
|
2023-01-08 02:32:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
-- 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()
|
2023-01-08 15:25:36 +01:00
|
|
|
vel.y = vel.y + (math.random() * self.min_max_jump_force_diff + self.min_jump_force)
|
2023-01-08 02:32:49 +01:00
|
|
|
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
|
|
|
|
2023-01-08 15:25:36 +01:00
|
|
|
-- apply bounciness if last_y_velocity was negative and now is 0
|
|
|
|
if self.last_y_velocity < 0 and vel.y == 0 then
|
|
|
|
vel.y = vel.y - self.last_y_velocity * self.bounciness
|
|
|
|
end
|
|
|
|
|
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)
|
|
|
|
|
2023-01-08 15:25:36 +01:00
|
|
|
self.last_y_velocity = vel.y
|
2023-01-08 00:11:47 +01:00
|
|
|
end
|
|
|
|
}
|
|
|
|
minetest.register_entity("amogus_entities:amogus", entity)
|