SUSSY AMOGUSES are no longer sad

This commit is contained in:
Looki2000 2023-01-08 15:25:36 +01:00
parent d8e220a006
commit ae81fd77fd

View File

@ -17,26 +17,26 @@ local entity = {
gravity = 9.81, -- m/s^2 gravity = 9.81, -- m/s^2
walk_acceletation_speed = 0.2, -- self explainatory walk_acceletation_speed = 0.2, -- self explainatory
jump_force = 20, -- self explainatory rotation_acceletation_speed = 3, -- self explainatory
friction = 0.5, -- friction (0.0 - no friction like perfectly smooth ice | 1.0 - full friction and can't even move) min_jump_force = 15, -- self explainatory
rotation_friction = 0.5, -- the same but for rotation max_jump_force = 25, -- self explainatory
bounciness = 0.5, -- bounciness (0.0 - no bounce at all | 1.0 - full bounce and bouces infinitely back to the same height)
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)
-------------------- --------------------
is_going_forward = true, is_going_forward = true,
block_lastly_in_front = false, block_lastly_in_front = false,
direction_velocity = 0, rotation_velocity = 0,
rotation_direction = nil,
last_y_velocity = 0,
on_activate = function(self, staticdata) on_activate = function(self, staticdata)
local direction = math.random() * 2 * math.pi self.object:set_yaw(math.random() * 2 * math.pi)
self.rotation_direction = math.random(-1, 1)
-- procesing config values -- self.min_max_jump_force_diff = self.max_jump_force - self.min_jump_force
--friction = 1 - self.friction
--rotation_friction = 1 - self.rotation_friction
bounciness = 1 - self.bounciness
-----------------------------
-- kill itself (debugging) -- kill itself (debugging)
--self.object:remove() --self.object:remove()
@ -47,7 +47,7 @@ local entity = {
on_step = function(self, dtime) on_step = function(self, dtime)
-- play amogus sound randomly -- play amogus sound randomly
if math.random(500) == 1 then if math.random(300) == 1 then
minetest.sound_play("amogus_sound", { minetest.sound_play("amogus_sound", {
pos = self.object:get_pos(), pos = self.object:get_pos(),
gain = 1.0, gain = 1.0,
@ -77,22 +77,30 @@ local entity = {
self.object:set_velocity(vel) self.object:set_velocity(vel)
end end
-- some chance of turning left or right
if math.random(50) == 1 then -- some chance of chaning rotation_direction to random value
self.object:set_yaw(self.object:get_yaw() + math.pi/2) if math.random(10) == 1 then
elseif math.random(50) == 1 then --self.rotation_direction = math.random(-1, 1)
self.object:set_yaw(self.object:get_yaw() - math.pi/2) local rand = math.random()
if rand < 0.2 then
self.rotation_direction = 1
elseif rand < 0.4 then
self.rotation_direction = -1
else
self.rotation_direction = 0
end
end end
-- 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)
-- 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 -- Make it also jump when some block is in front of it
@ -106,7 +114,7 @@ local entity = {
if self.block_lastly_in_front == false then if self.block_lastly_in_front == false then
self.block_lastly_in_front = true self.block_lastly_in_front = true
local vel = self.object:get_velocity() local vel = self.object:get_velocity()
vel.y = vel.y + self.jump_force vel.y = vel.y + (math.random() * self.min_max_jump_force_diff + self.min_jump_force)
self.object:set_velocity(vel) self.object:set_velocity(vel)
end end
else else
@ -114,11 +122,14 @@ local entity = {
end end
local vel = self.object:get_velocity() local vel = self.object:get_velocity()
-- 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
-- change velocity by gravity -- change velocity by gravity
vel.y = vel.y - self.gravity * dtime * 2 vel.y = vel.y - self.gravity * dtime * 2
@ -128,6 +139,8 @@ local entity = {
self.object:set_velocity(vel) self.object:set_velocity(vel)
self.last_y_velocity = vel.y
end end
} }
minetest.register_entity("amogus_entities:amogus", entity) minetest.register_entity("amogus_entities:amogus", entity)