update entities physics & fix jumping mobs
This commit is contained in:
parent
93e7ae159a
commit
67a5741ed2
@ -50,13 +50,24 @@ function lower(speed, delta, vel)
|
|||||||
vec3.add(vel, {0, -speed * delta * props.movement_speed, 0}, vel))
|
vec3.add(vel, {0, -speed * delta * props.movement_speed, 0}, vel))
|
||||||
end
|
end
|
||||||
|
|
||||||
function move_horizontal(speed, dir, vel)
|
local function move_horizontal(speed, dir, vel)
|
||||||
vel = vel or body:get_vel()
|
vel = vel or body:get_vel()
|
||||||
if vec3.length(dir) > 0.0 then
|
if vec3.length(dir) > 0.0 then
|
||||||
vec3.normalize(dir, dir)
|
vec3.normalize(dir, dir)
|
||||||
|
|
||||||
vel[1] = dir[1] * speed
|
local magnitude = vec3.length({vel[1], 0, vel[3]})
|
||||||
vel[3] = dir[3] * speed
|
|
||||||
|
if magnitude <= 1e-4 or (magnitude < speed or vec3.dot(
|
||||||
|
{vel[1] / magnitude, 0.0, vel[3] / magnitude}, dir) < 0.9)
|
||||||
|
then
|
||||||
|
vel[1] = vel[1] + dir[1] * speed * 0.8
|
||||||
|
vel[3] = vel[3] + dir[3] * speed * 0.8
|
||||||
|
end
|
||||||
|
magnitude = vec3.length({vel[1], 0, vel[3]})
|
||||||
|
if vec3.dot({vel[1] / magnitude, 0.0, vel[3] / magnitude}, dir) > 0.5 then
|
||||||
|
vel[1] = vel[1] / magnitude * speed
|
||||||
|
vel[3] = vel[3] / magnitude * speed
|
||||||
|
end
|
||||||
end
|
end
|
||||||
body:set_vel(vel)
|
body:set_vel(vel)
|
||||||
end
|
end
|
||||||
@ -77,7 +88,6 @@ end
|
|||||||
local prev_angle = 0.0
|
local prev_angle = 0.0
|
||||||
local headIndex = rig:index("head")
|
local headIndex = rig:index("head")
|
||||||
|
|
||||||
|
|
||||||
-- todo: move somewhere
|
-- todo: move somewhere
|
||||||
local watchtimer = math.random(0, 1000)
|
local watchtimer = math.random(0, 1000)
|
||||||
local function update_head()
|
local function update_head()
|
||||||
@ -103,8 +113,6 @@ end
|
|||||||
|
|
||||||
local function follow_waypoints(pathfinding, delta)
|
local function follow_waypoints(pathfinding, delta)
|
||||||
local pos = tsf:get_pos()
|
local pos = tsf:get_pos()
|
||||||
pathfinding.set_target(vec3.add(pos,
|
|
||||||
{math.random(-15, 15), math.random(-2, 2), math.random(-15, 15)}))
|
|
||||||
local waypoint = pathfinding.next_waypoint()
|
local waypoint = pathfinding.next_waypoint()
|
||||||
if not waypoint then
|
if not waypoint then
|
||||||
return
|
return
|
||||||
|
|||||||
@ -50,8 +50,8 @@ end
|
|||||||
|
|
||||||
function on_update()
|
function on_update()
|
||||||
if not started then
|
if not started then
|
||||||
if body:is_grounded() then
|
|
||||||
frameid = frameid + 1
|
frameid = frameid + 1
|
||||||
|
if body:is_grounded() then
|
||||||
if target and (frameid % refresh_internal == 1 or not route) then
|
if target and (frameid % refresh_internal == 1 or not route) then
|
||||||
pathfinding.make_route_async(agent, tsf:get_pos(), target)
|
pathfinding.make_route_async(agent, tsf:get_pos(), target)
|
||||||
started = true
|
started = true
|
||||||
|
|||||||
@ -45,11 +45,6 @@ void PhysicsSolver::step(
|
|||||||
colisionCalc(chunks, hitbox, vel, pos, half,
|
colisionCalc(chunks, hitbox, vel, pos, half,
|
||||||
(prevGrounded && gravityScale > 0.0f) ? 0.5f : 0.0f);
|
(prevGrounded && gravityScale > 0.0f) ? 0.5f : 0.0f);
|
||||||
}
|
}
|
||||||
vel.x /= 1.0f + dt * linearDamping;
|
|
||||||
vel.z /= 1.0f + dt * linearDamping;
|
|
||||||
if (hitbox.verticalDamping) {
|
|
||||||
vel.y /= 1.0f + dt * linearDamping;
|
|
||||||
}
|
|
||||||
|
|
||||||
pos += vel * dt + gravity * gravityScale * dt * dt * 0.5f;
|
pos += vel * dt + gravity * gravityScale * dt * dt * 0.5f;
|
||||||
if (hitbox.grounded && pos.y < py) {
|
if (hitbox.grounded && pos.y < py) {
|
||||||
@ -89,6 +84,12 @@ void PhysicsSolver::step(
|
|||||||
hitbox.grounded = true;
|
hitbox.grounded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
vel.x /= 1.0f + delta * linearDamping;
|
||||||
|
vel.z /= 1.0f + delta * linearDamping;
|
||||||
|
if (hitbox.verticalDamping) {
|
||||||
|
vel.y /= 1.0f + delta * linearDamping;
|
||||||
|
}
|
||||||
|
|
||||||
AABB aabb;
|
AABB aabb;
|
||||||
aabb.a = hitbox.position - hitbox.halfsize;
|
aabb.a = hitbox.position - hitbox.halfsize;
|
||||||
aabb.b = hitbox.position + hitbox.halfsize;
|
aabb.b = hitbox.position + hitbox.halfsize;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user