Exported door model, added CollisionManager#on_ground?(entity), made gravity work in PhyisicsManager if Entity has physics enabled, updated test map

This commit is contained in:
2019-09-25 18:17:18 -05:00
parent 954c6899be
commit ecee086590
10 changed files with 247 additions and 47 deletions

View File

@@ -82,5 +82,29 @@ class IMICFPS
return box
end
def on_ground?(entity) # TODO: Use some form of caching to speed this up
on_ground = false
@collisions.detect do |a, b|
next unless entity == a || entity == b
vs = a
vs = b if a == entity
broadphase = search(Ray.new(entity.position, Vector.new(0, -1, 0), entity.velocity.y.abs))
broadphase.detect do |ent|
ray = Ray.new(entity.position - ent.position, Vector.new(0, -1, 0))
if ent.model.aabb_tree.search(ray).size > 0
on_ground = true
return true
end
end
break if on_ground
end
return on_ground
end
end
end

View File

@@ -15,21 +15,24 @@ class IMICFPS
end
def resolve(entity, other)
if other.is_a?(Terrain)
entity.velocity.y = 0 if entity.velocity.y < 0
else
entity.velocity.y = other.velocity.y if other.velocity.y < entity.velocity.y && entity.velocity.y < 0
end
entity.velocity.y = other.velocity.y if other.velocity.y < entity.velocity.y && entity.velocity.y < 0
end
def simulate
@collision_manager.game_state.entities.each do |entity|
entity.velocity.x *= entity.drag
entity.velocity.z *= entity.drag
entity.position.x += entity.velocity.x * entity.delta_time
entity.position.y += entity.velocity.y * entity.delta_time
entity.position.z += entity.velocity.z * entity.delta_time
on_ground = @collision_manager.on_ground?(entity)
entity.velocity.x *= entity.drag
entity.velocity.z *= entity.drag
if on_ground
entity.velocity.y = 0
else
entity.velocity.y -= IMICFPS::GRAVITY * entity.delta_time if entity.physics
end
end
end
end