mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 23:52:35 +00:00
PhysicsManager now has a job, CollisionManager enabled, using Player velocity instead of position for movement controls, added Entity drag, added spaces
This commit is contained in:
@@ -28,7 +28,7 @@ class IMICFPS
|
||||
@physics_manager.update
|
||||
|
||||
collisions.each do |ent, list|
|
||||
# puts "#{ent.class} -> [#{list.map{|e| e.class}.join(', ')}] (#{Gosu.milliseconds})"
|
||||
# puts "#{ent.class} -> [#{list.map { |e| e.class }.join(', ')}] (#{Gosu.milliseconds})"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -57,12 +57,12 @@ class IMICFPS
|
||||
# aabb vs aabb
|
||||
next unless entity.bounding_box.intersect?(ent.bounding_box)
|
||||
# entity model aabb tree vs ent model aabb tree
|
||||
# ent_tree_search = ent.model.aabb_tree.search(localize_entity_bounding_box(entity, ent), true)
|
||||
# next if ent_tree_search.size == 0
|
||||
ent_tree_search = ent.model.aabb_tree.search(localize_entity_bounding_box(entity, ent), true)
|
||||
next if ent_tree_search.size == 0
|
||||
|
||||
# puts "#{ent.class} -> #{ent_tree_search.size} (#{Gosu.milliseconds})"
|
||||
|
||||
# entity.position.y = ent_tree_search.first.object.vertices.first.y if entity.is_a?(Player) && ent.is_a?(Terrain)
|
||||
entity.position.y = ent_tree_search.first.object.vertices.first.y if entity.is_a?(Player) && ent.is_a?(Terrain)
|
||||
|
||||
@collisions[entity] = _collisions
|
||||
end
|
||||
|
||||
@@ -10,9 +10,27 @@ class IMICFPS
|
||||
resolve(entity, other)
|
||||
end
|
||||
end
|
||||
|
||||
simulate
|
||||
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
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user