Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | toblin |
Why do my Area objects repel each other? I.e. why can’t they pass through each other without being affected by physics? How do I make them be able to pass each other through?
The blue solid spheres seen here are RigidBodies with their own CollisionShapes. The large outer “invisible” spheres are the CollisionShapes of the areas attached to the RigidBodies. I’m expecting that the RigidBodies should not be able to pass each other through. I do however expect the large collisionShapes to pass each other through.
Below is the custom script that defines the RigidBodies with the Area and CollisionShapes attached. The two ball-entities seen in the GIF are instances of this script.
# Cell.gd: Custom script that is not attached to a Node.
# Is instanced in Spatial.gd below
extends RigidBody
var area
var outersphere
var innersphere
var visualsphere
var collisionshape_inner
var collisionshape_outer
func _ready():
# create shapes
outersphere = SphereShape.new()
outersphere.radius = 4.0
innersphere = SphereShape.new()
visualsphere = CSGSphere.new()
# create collision shapes
collisionshape_inner = CollisionShape.new()
collisionshape_inner.set_shape(innersphere)
collisionshape_outer = CollisionShape.new()
collisionshape_outer.set_shape(outersphere)
# add collisionshape_inner as child to rigidBody
add_child(collisionshape_inner)
# add an area to the rigidBody
area = Area.new()
add_child(area)
# add collisionshape_outer to the area
add_child_below_node(area, collisionshape_outer)
# add visualshape to rigidbody
add_child(visualsphere)
The main scene is a Spatial.tscn, with the following attached script:
# Spatial.gd. Attached as a script to a Spatial node in the
# node tree and main scene
extends Spatial
var Cell = load("res://Cell.gd")
var zygote = Cell.new()
var zygote2 = Cell.new()
func _ready():
add_child(zygote)
add_child(zygote2)
zygote.translation = Vector3(-20,0,0)
zygote2.translation = Vector3(20,0,0)
func _physics_process(delta):
var v_21 = zygote.translation - zygote2.translation
var v_12 = -v_21
zygote.add_central_force( v_12*1 )
zygote2.add_central_force( v_21*1 )