@cybereality said:
It might actually be more optimized to loop in a central location (rather than having each rigid body have it's own buoyancy code).
Yes I agree with that. That's what I'm currently doing as well. Thank you a lot!
Here is the updated version of the code above:
extends Area
var Vmass = []
var objects = []
func _process(delta):
if objects:
for i in range(0, objects.size()):
objects[i].add_central_force(Vector3(0, Vmass[i], 0))
func _on_Area_body_entered(body):
objects.append(body)
Vmass.append(body.weight)
func _on_Area_body_exited(body):
objects.erase(body)
Vmass.erase(body.weight)
Hope this can help others out.