SUSSY AMOGUSES are no longer sad
This commit is contained in:
parent
d8e220a006
commit
ae81fd77fd
@ -17,26 +17,26 @@ local entity = {
|
||||
gravity = 9.81, -- m/s^2
|
||||
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
--------------------
|
||||
|
||||
|
||||
is_going_forward = true,
|
||||
block_lastly_in_front = false,
|
||||
direction_velocity = 0,
|
||||
rotation_velocity = 0,
|
||||
rotation_direction = nil,
|
||||
last_y_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
|
||||
-----------------------------
|
||||
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
|
||||
|
||||
-- kill itself (debugging)
|
||||
--self.object:remove()
|
||||
@ -47,7 +47,7 @@ local entity = {
|
||||
on_step = function(self, dtime)
|
||||
|
||||
-- play amogus sound randomly
|
||||
if math.random(500) == 1 then
|
||||
if math.random(300) == 1 then
|
||||
minetest.sound_play("amogus_sound", {
|
||||
pos = self.object:get_pos(),
|
||||
gain = 1.0,
|
||||
@ -77,22 +77,30 @@ local entity = {
|
||||
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)
|
||||
|
||||
-- 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()
|
||||
|
||||
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
|
||||
|
||||
-- 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)
|
||||
|
||||
|
||||
|
||||
-- print curent amogus entity y position
|
||||
--minetest.chat_send_player("singleplayer", "Y: " .. pos.y)
|
||||
|
||||
-- print delta time
|
||||
minetest.chat_send_player("singleplayer", "dtime: " .. dtime)
|
||||
-- apply rotation_friction
|
||||
self.rotation_velocity = self.rotation_velocity * (1 - self.rotation_friction * dtime)
|
||||
|
||||
|
||||
-- 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
|
||||
self.block_lastly_in_front = true
|
||||
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)
|
||||
end
|
||||
else
|
||||
@ -115,10 +123,13 @@ local entity = {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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
|
||||
vel.y = vel.y - self.gravity * dtime * 2
|
||||
|
||||
@ -128,6 +139,8 @@ local entity = {
|
||||
|
||||
self.object:set_velocity(vel)
|
||||
|
||||
self.last_y_velocity = vel.y
|
||||
|
||||
end
|
||||
}
|
||||
minetest.register_entity("amogus_entities:amogus", entity)
|
Loading…
Reference in New Issue
Block a user