Use better algorithm for correcting too fast mob movement

This commit is contained in:
sapier 2013-12-16 18:32:40 +01:00
parent 65b0f4739a
commit 73fb95bfb4

View File

@ -524,13 +524,17 @@ function mgen_follow.checkspeed(entity)
if (xzspeed > entity.data.movement.max_speed) then
--preserver orientation when correcting speed
local dir = mobf_calc_yaw(current_velocity.x,current_velocity.z)
local velocity_to_set = mobf_calc_vector_components(dir,entity.data.movement.max_speed * 0.25)
local direction = mobf_calc_yaw(current_velocity.x,
current_velocity.z)
velocity_to_set.y=current_velocity.y
--reduce speed to 90% of current speed
local new_speed = mobf_calc_vector_components(direction,xzspeed*0.9)
entity.object:setvelocity(velocity_to_set)
local current_accel = entity.object:getacceleration()
new_speed.y = current_velocity.y
entity.object:setvelocity(new_speed)
entity.object:setacceleration({x=0,y=current_accel.y,z=0})
return true
end