9func add_force(body:Dictionary, force:Vector2) -> Dictionary:
10 var next = body.duplicate(true)
11 next[
"force"] = next.get(
"force", Vector2.ZERO) + force
16func apply_impulse(body:Dictionary, impulse:Vector2) -> Dictionary:
17 var next = body.duplicate(true)
18 if bool(next.get(
"static", false)):
20 next[
"velocity"] = next.get(
"velocity", Vector2.ZERO) + impulse *
float(next.get(
"inv_mass", 0.0))
25func integrate(body:Dictionary, delta:float, gravity:Vector2 = Vector2.ZERO, damping:float = 0.0) -> Dictionary:
26 var next = body.duplicate(true)
27 if bool(next.get(
"static", false)):
28 next[
"force"] = Vector2.ZERO
29 next[
"acceleration"] = Vector2.ZERO
31 var inv_mass =
float(next.get(
"inv_mass", 1.0))
32 var acceleration = gravity + next.get(
"force", Vector2.ZERO) * inv_mass
33 var velocity = next.get(
"velocity", Vector2.ZERO) + acceleration * delta
35 velocity *= max(0.0, 1.0 - damping * delta)
36 next[
"previous_position"] = next.get(
"position", Vector2.ZERO)
37 next[
"position"] = next.get(
"position", Vector2.ZERO) + velocity * delta
38 next[
"velocity"] = velocity
39 next[
"acceleration"] = acceleration
40 next[
"force"] = Vector2.ZERO