Disabling a RigidBodyControl locks it’s translation

The setup: My player spatial has a child node attached to it which i call the inventoryHook. This node is rotated by a control and again has some child nodes attached to it which act as hooks to inventory items themself. So basically i have a number of nodes rotating around my player. Some of them are missiles which should be physical objects in the scene and therefor have a RigidBodyControl attached to them which is disabled by default to keep them floating around the player.



The problem: When one of the missiles is fired the PhysicsControl needs to be enabled, but doing so seems to warp them back in the starting position. If instead the control is detached and reattached to the missile i get the desired behaviour of launching them from the current position.



So my question is if this is the intended use or if i’m missing some mechanic?



First here is the abstract missile class. I know the initialization of the control is not clean programming but at least it should be correct.

[java]

public abstract class Missile implements IMovable {



protected final Node parent;

protected final Spatial missile;

protected PhysicsSpace physicsSpace;

protected RigidBodyControl control;

protected float launchSpeed;

private Vector3f gravity = Vector3f.UNIT_Y.negate();

private float gravitySquared;



public Missile(Node parent, Spatial missile, PhysicsSpace ps, float launchSpeed) {

this.parent = parent;

this.missile = missile;

this.physicsSpace = ps;

this.launchSpeed = launchSpeed;



initControl();

}



private void initControl() {

control = new RigidBodyControl(new SphereCollisionShape(.25f));

control.setPhysicsSpace(physicsSpace);

control.setEnabled(false);

missile.addControl(control);



precalculateCoefficients();

}



public abstract void shoot(Vector3f target);



}

[/java]



And here is a subclass of the missile class

[java]

public class Book extends Missile {



public Book(Node parent, Spatial missile, PhysicsSpace ps) {

super(parent, missile, ps, 10f);

}



@Override

public void shoot(Vector3f target) {

/* Normally here would be a call to a method providing a firing solution but since i’m just interested in the behaviour described above dropping the missile should suffice to see if everything is ok. This line warps the missile back to the start. /

control.setEnabled(true);

/
Here is what works well. */

missile.removeControl(control);

missile.addControl(control);

}

}

[/java]

As the javadoc states the position of the spatial is only applied to the control when its added. To set the physics location before reenabling, use RigidBodyControl.setPhysicsLocation()

1 Like

Oh ok. I should read more carefully.



Thx for the quick reply.