Collision layers and entity rendering offsets
This commit is contained in:
@@ -26,9 +26,29 @@ Trigger_Overlap :: struct {
|
||||
|
||||
MAX_TRIGGER_OVERLAPS :: 16;
|
||||
|
||||
Collision_Layers :: enum_flags {
|
||||
NONE;
|
||||
|
||||
LAYER1;
|
||||
LAYER2;
|
||||
LAYER3;
|
||||
LAYER4;
|
||||
LAYER5;
|
||||
LAYER6;
|
||||
LAYER7;
|
||||
LAYER8;
|
||||
LAYER9;
|
||||
LAYER10;
|
||||
|
||||
ALL :: .LAYER1 | LAYER2 | .LAYER3 | .LAYER4 | .LAYER5 | .LAYER6 | .LAYER7 | .LAYER8 | .LAYER9 | .LAYER10;
|
||||
}
|
||||
|
||||
Collider :: struct {
|
||||
type : Collider_Type;
|
||||
|
||||
layer: Collision_Layers = .LAYER1;
|
||||
collides_with_layers: Collision_Layers = .LAYER1;
|
||||
|
||||
aabb: AABB;
|
||||
override_aabb: bool;
|
||||
union {
|
||||
@@ -166,6 +186,10 @@ add_trigger_overlap_if_new :: (e: *Entity, other_e: *Entity) {
|
||||
e.collider.num_overlaps += 1;
|
||||
}
|
||||
|
||||
can_collide :: (e: *Entity, other: *Entity) -> bool {
|
||||
return xx (e.collider.collides_with_layers & other.collider.layer);
|
||||
}
|
||||
|
||||
physics_step :: (scene: *Scene, timestep: float) {
|
||||
update_gravity(scene, timestep);
|
||||
update_positions(scene, timestep);
|
||||
@@ -179,6 +203,7 @@ physics_step :: (scene: *Scene, timestep: float) {
|
||||
for other_e: scene.entities {
|
||||
if e == other_e continue;
|
||||
if other_e.collider.ignore continue;
|
||||
if !can_collide(e, other_e) continue;
|
||||
|
||||
if other_e.flags & .COLLISION {
|
||||
point := gjk(e.collider, other_e.collider);
|
||||
|
||||
Reference in New Issue
Block a user