0 votes

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.

enter image description here

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 )
asked Apr 6 in Engine by toblin (85 points)
edited Apr 6 by toblin

1 Answer

+2 votes
Best answer

Add_child_below_node doesnt add the child to the second node but as a brother(aka same parent)
Example
so what you want to do is use the get_node or $ to get the area node and then do something like

 $AreaNodeName.add_child(Collision Sphere)

or

 get_node(AreaNodeName).add_child(Collision Sphere)
answered Apr 6 by rustyStriker (1,067 points)
selected Apr 6 by toblin
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.