Half finish horse (riding logic, etc)

This commit is contained in:
jordan4ibanez 2021-04-23 15:53:01 -04:00
parent f64f8e31e3
commit 189c0ad157
7 changed files with 62 additions and 32 deletions

View File

@ -672,6 +672,14 @@ mobs.mob_step = function(self, dtime)
if self.do_custom then
-- when false skip going any further
if self.do_custom(self, dtime) == false then
--this needs to be here or the mob becomes immortal
if self.pause_timer > 0 then
self.pause_timer = self.pause_timer - dtime
--perfectly reset pause_timer
if self.pause_timer < 0 then
self.pause_timer = 0
end
end
--this overrides internal lua collision detection
return
end

View File

@ -39,10 +39,10 @@ mobs.collision = function(self)
end
for _,object in ipairs(minetest_get_objects_inside_radius(pos, radius*1.25)) do
if object and object ~= self.object and (object:is_player() or (object:get_luaentity() and object:get_luaentity()._cmi_is_mob == true)) then--and
if object and object ~= self.object and (object:is_player() or (object:get_luaentity() and object:get_luaentity()._cmi_is_mob == true)) and
--don't collide with rider, rider don't collide with thing
--(not object:get_attach() or (object:get_attach() and object:get_attach() ~= self.object)) and
--(not self.object:get_attach() or (self.object:get_attach() and self.object:get_attach() ~= object)) then
(not object:get_attach() or (object:get_attach() and object:get_attach() ~= self.object)) and
(not self.object:get_attach() or (self.object:get_attach() and self.object:get_attach() ~= object)) then
--stop infinite loop
collision_count = collision_count + 1
if collision_count > 100 then

View File

@ -89,6 +89,20 @@ end
mobs.death_logic = function(self, dtime)
self.death_animation_timer = self.death_animation_timer + dtime
--get all attached entities and sort through them
local attached_entities = self.object:get_children()
if #attached_entities > 0 then
for _,entity in pairs(attached_entities) do
--kick the player off
if entity:is_player() then
mobs.detach(entity)
--kick mobs off
--if there is scaling issues, this needs an additional check
else
entity:set_detach()
end
end
end
--the final POOF of a mob despawning
if self.death_animation_timer >= 1.25 then

View File

@ -206,21 +206,30 @@ function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime)
-- move forwards
if ctrl.up then
entity.v = entity.v + entity.accel / 10
mobs.set_velocity(entity, entity.run_velocity)
mobs.set_mob_animation(entity, moving_anim)
-- move backwards
elseif ctrl.down then
if entity.max_speed_reverse == 0 and entity.v == 0 then
return
mobs.set_velocity(entity, -entity.run_velocity)
mobs.set_mob_animation(entity, moving_anim)
--halt
else
mobs.set_velocity(entity, 0)
mobs.set_mob_animation(entity, stand_anim)
end
entity.v = entity.v - entity.accel / 10
end
-- fix mob rotation
-- mob rotation
entity.object:set_yaw(entity.driver:get_look_horizontal() - entity.rotate)
entity.yaw = entity.driver:get_look_horizontal() - entity.rotate
--[[
if can_fly then
-- fly up
@ -244,32 +253,21 @@ function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime)
end
else
]]--
-- jump
if ctrl.jump then
if velo.y == 0 then
velo.y = velo.y + entity.jump_height
acce_y = acce_y + (acce_y * 3) + 1
end
mobs.jump(entity)
end
end
end
-- if not moving then set animation and return
if entity.v == 0 and velo.x == 0 and velo.y == 0 and velo.z == 0 then
if stand_anim then
mobs:set_animation(entity, stand_anim)
end
return
--end
end
--[[
-- set moving animation
if moving_anim then
mobs:set_animation(entity, moving_anim)
mobs:set_mob_animation(entity, moving_anim)
end
-- Stop!
@ -383,6 +381,7 @@ function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime)
end
entity.v2 = v
]]--
end
@ -390,6 +389,10 @@ end
function mobs.fly(entity, dtime, speed, shoots, arrow, moving_anim, stand_anim)
if true then
print("succ")
return
end
local ctrl = entity.driver:get_player_control()
local velo = entity.object:get_velocity()
local dir = entity.driver:get_look_dir()
@ -440,9 +443,9 @@ function mobs.fly(entity, dtime, speed, shoots, arrow, moving_anim, stand_anim)
-- change animation if stopped
if velo.x == 0 and velo.y == 0 and velo.z == 0 then
mobs:set_animation(entity, stand_anim)
mobs:set_mob_animation(entity, stand_anim)
else
-- moving animation
mobs:set_animation(entity, moving_anim)
mobs:set_mob_animation(entity, moving_anim)
end
end

View File

@ -165,6 +165,8 @@ Overworld regular:
local mobs_spawn = minetest.settings:get_bool("mobs_spawn", true) ~= false
mobs_spawn = false
-- count how many mobs are in an area
local count_mobs = function(pos)
local num = 0

View File

@ -87,6 +87,9 @@ local horse = {
spawn_class = "passive",
visual = "mesh",
mesh = "mobs_mc_horse.b3d",
rotate = 270,
walk_velocity = 1,
run_velocity = 8,
visual_size = {x=3.0, y=3.0},
collisionbox = {-0.69825, -0.01, -0.69825, 0.69825, 1.59, 0.69825},
animation = {
@ -96,7 +99,7 @@ local horse = {
walk_speed = 25,
walk_start = 0,
walk_end = 40,
run_speed = 60,
run_speed = 120,
run_start = 0,
run_end = 40,
},
@ -181,7 +184,7 @@ local horse = {
-- if driver present and horse has a saddle allow control of horse
if self.driver and self._saddle then
mobs.drive(self, "walk", "stand", false, dtime)
mobs.drive(self, "run", "stand", false, dtime)
return false -- skip rest of mob functions
end