c

Lighting jolt jumps from empty space?

carlo_montoya

I wrote the code as instructed but I noticed that if there is one PhysicsBody2D inside the JumpArea, the jolt jumps from the Cast To point to the "Asteroid" as illustrated.

I added this condition before running the inner loop to 'fix it'

  if is_colliding():

   for _i in range(min(max_bounces, _secondary_bodies.size())):
    var _body = _secondary_bodies[_i]
    jolt = lightning_jolt.instance()
    add_child(jolt)
    jolt.create(_start, _body.global_position)
    _start = _body.global_position


Raycast collisions trigger the jolts from PhysicsBody2D to another as described in this tutorial.