Skip to content

Commit

Permalink
Use _integrate_forces to detect blaster collisions, even with asteroids
Browse files Browse the repository at this point in the history
  • Loading branch information
jspahrsummers committed Jul 27, 2024
1 parent 94426a4 commit bf23436
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
8 changes: 4 additions & 4 deletions fx/asteroids/asteroid_field.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ func _enter_tree() -> void:
PhysicsServer3D.body_set_state(physics_body, PhysicsServer3D.BODY_STATE_ANGULAR_VELOCITY, angular_velocity)
PhysicsServer3D.body_set_state(physics_body, PhysicsServer3D.BODY_STATE_LINEAR_VELOCITY, linear_velocity)
PhysicsServer3D.body_set_space(physics_body, self.get_world_3d().space)
PhysicsServer3D.body_set_force_integration_callback(physics_body, _body_moved, i)
PhysicsServer3D.body_set_collision_layer(physics_body, 1)
PhysicsServer3D.body_set_collision_mask(physics_body, 2)
PhysicsServer3D.body_set_force_integration_callback(physics_body, _force_integration_callback, i)
PhysicsServer3D.body_set_collision_layer(physics_body, 0b01)
PhysicsServer3D.body_set_collision_mask(physics_body, 0b10)
PhysicsServer3D.body_set_axis_lock(physics_body, PhysicsServer3D.BODY_AXIS_LINEAR_Y, true)
self._created_rids.append(physics_body)

Expand All @@ -36,7 +36,7 @@ func _exit_tree() -> void:

self._created_rids.clear()

func _body_moved(state: PhysicsDirectBodyState3D, index: int) -> void:
func _force_integration_callback(state: PhysicsDirectBodyState3D, index: int) -> void:
var mesh_transform := state.transform

# Overwrite the physics scale from the multimesh, because it gets lost for some reason otherwise.
Expand Down
11 changes: 9 additions & 2 deletions mechanics/combat/weapons/blaster/blaster_bolt.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@ func _process(_delta: float) -> void:
if Time.get_ticks_msec() - self._spawn_time_msec > self.lifetime_msec:
self.queue_free()

func _on_body_entered(body: Node) -> void:
func _integrate_forces(state: PhysicsDirectBodyState3D) -> void:
if state.get_contact_count() == 0:
return

var explosion_instance: AnimatedSprite3D = self.explosion.instantiate()
self.add_sibling(explosion_instance)
explosion_instance.global_position = self.global_position
explosion_instance.global_rotation = self.global_rotation
explosion_instance.scale = Vector3.ONE * 0.2

CombatObject.damage_combat_object_inside(body, self.damage)
var collider := state.get_contact_collider_object(0)
var node := collider as Node
if node:
CombatObject.damage_combat_object_inside(node, self.damage)

self.queue_free()
4 changes: 2 additions & 2 deletions mechanics/combat/weapons/blaster/blaster_bolt.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ lock_rotation = true
continuous_cd = true
max_contacts_reported = 1
contact_monitor = true
linear_damp_mode = 1
angular_velocity = Vector3(3.63316e-14, 3.63316e-14, 3.63316e-14)
angular_damp_mode = 1
script = ExtResource("1_nmdx1")
damage = SubResource("Resource_a466u")
explosion = ExtResource("3_0y0wg")
Expand Down Expand Up @@ -63,5 +65,3 @@ mesh = SubResource("QuadMesh_fxvid")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.510476)
stream = ExtResource("5_dbrcg")
autoplay = true

[connection signal="body_entered" from="." to="." method="_on_body_entered"]

0 comments on commit bf23436

Please sign in to comment.