0 votes

Hi forum,

I'm trying to optimize using servers, and I need help creating an object using the PhysicsServer (PS) and VirtualServer (VS).

Here's what I would like to create, as described by how I would make it in the Editor. I would like to have a RigidBody with a CollisionShape, an Area with another CollisionShape, and a CSGSphere. Looking something like this:

---- CollisionShape
---- Area
---- ---- CollisionShape
---- CSGSphere

What I've done so far is to try to create a single instance in a Spatial node with the following script. I can't figure out how to attach the area to the RigidBody however.

extends Spatial

var body
var bodyshape

var area
var areashape

func _ready():
    # Create the body.
    body = PhysicsServer.body_create()
    PhysicsServer.body_set_mode( body, PhysicsServer.BODY_MODE_RIGID )
    bodyshape = PhysicsServer.shape_create( PhysicsServer.SHAPE_SPHERE )
    PhysicsServer.body_add_shape(body, bodyshape)

    # Create area
    area = PhysicsServer.area_create()
    areashape = PhysicsServer.shape_create( PhysicsServer.SHAPE_SPHERE)
    PhysicsServer.area_add_shape ( area, areashape)

    # Set space, so it collides in the same space as current scene.
    PhysicsServer.body_set_space( body, get_world().space )
    PhysicsServer.area_set_space( area, get_world().space )

    # Move initial position.
    PhysicsServer.body_set_state(body, PhysicsServer.BODY_STATE_TRANSFORM, Transform(Vector3(0,0,0), Vector3(10,0,0)) )

    PhysicsServer.body_set_force_integration_callback(body, self, "_body_moved", 0)

Summarized question:

  1. How to create the above-described object using VS and PS?
  2. A subquestion: how to attach an Area to RigidBody using VS and PS?

Thanks a lot in advance,

in Engine by (137 points)

Please log in or register to answer this question.

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.