Multiple controls

Hello, I have a problem with using multiple controls, specifically a rigidbodycontrol and an abstract control. I use the abstract control for movement:`public class WeaponControl extends AbstractControl {

private Vector3f dM;
private Node rootNode;
private int t = 4000;
public WeaponControl(Vector3f dM, Node rootNode) {
    this.dM = dM;
    this.rootNode = rootNode;
}

@Override
protected void controlUpdate(float tpf) {
    spatial.move(dM);
    t--;
    if (t < 0) {
        rootNode.detachChild(spatial);
    }
}

@Override
protected void controlRender(RenderManager rm, ViewPort vp) {
}

public Control cloneForSpatial(Spatial spatial) {
    WeaponControl control = new WeaponControl(dM, rootNode);
    control.setSpatial(spatial);
    return control;
}

}`

I use the prigidbodycontrol for collision detection:

private void setUpCollision() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
SphereCollisionShape bulletShape =
new SphereCollisionShape(1.0f);
RigidBodyControl kWC =
new RigidBodyControl(bulletShape, 123.0f);
kineticWeaponModel.addControl(kWC);
}

The topic creation thing is acting strangely for me so this is the problem:
I have a problem with using multiple controls, specifically a rigidbodycontrol and an abstract control.
I use the abstract control for movement:

public class WeaponControl extends AbstractControl {

private Vector3f dM;
private Node rootNode;
private int t = 4000;
public WeaponControl(Vector3f dM, Node rootNode) {
    this.dM = dM; //dM is a vector for the direction and speed of the kinetic weapon
    this.rootNode = rootNode;
}

@Override
protected void controlUpdate(float tpf) {
    spatial.move(dM);
    t--;
    if (t < 0) {
        rootNode.detachChild(spatial);
    }
}

@Override
protected void controlRender(RenderManager rm, ViewPort vp) {
}

public Control cloneForSpatial(Spatial spatial) {
    WeaponControl control = new WeaponControl(dM, rootNode);
    control.setSpatial(spatial);
    return control;
}

}

And the rigidbodycontrol for collision detection:

private void setUpCollision() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
SphereCollisionShape bulletShape =
new SphereCollisionShape(1.0f);
RigidBodyControl kWC =
new RigidBodyControl(bulletShape, 123.0f);
kineticWeaponModel.addControl(kWC);
}

the problem is that the rigidbodycontrol seems to be overriding the abstactcontrol because the kinetic weapon does not appear where is should be.

I am not sure about what your trouble is. You can have more than a control in a Spatial with no problems.
Did you attach a ‘WeaponControl’ to your ‘kineticWeaponModel’?

Wait… you attached a physics-based control (that will move the spatial based on physics and override all other position) and then wonder why setting the position in a different control doesn’t work?

Which do you want? Physics based movement or manual movement? If you want both then you will have to somehow move the rigid body.

I thought the collisionshape would move with the spatial, but as it doesn’t, do you know how i would move a rigid body? i have the vector3f of the kinetic weapon when it gets created.
Thanks!
And yes the kinetic weapon has the weaponcontrol attached yes!

Set the RigidBody to kinematic, if you want to use spatial.move ()

otherwise use forces on the RigidBody, for proper physics interactions:
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:physics#forcesmoving_dynamic_objects

i tried setting to kinematic but it still doesnt collide with a mesh collision shape. Is this because i am using multiple classes, the kinetic weapon is in one class, and has a new bulletappstate and extends simpleapplication because i need statemanager to add the bulletappstate, the enemy class has a new bulletappstate as well. What is the purpose of bulletappstate? Should i only make one bulletappstate in my main class and link to it whenever i need it?

“extends simpleapplication”

How many applications do you need in your application? Doesn’t that sound silly?

If you need something in another class then just give it to it.

Ok I’ve cleared up the extends simple application thing, so now it receives the bulletappstate from the main class. I enabled debugging for the collision shape and it shows for the ship the correct mesh shape, and for the torpedo the correct sphere shape, however when the torpedo hits the ship, it does not get stopped, why is this?
Thanks for the help so far!

however when i disable kinematics on the torpedo, it no longer moves, but gets created at 0, 0, 0. However it does collide with the enemy ship. When i turn kinematics on, no collision occurs but the movement and starting location works perfectly. How can i make it collide and keep kinematics. (I also want kinematics because i don’t want objects to fall)

kinematics turns off physics essentially.

Just do it all in physics - you can’t half half physics and half not physics.

Set gravity to 0.
Apply a force to accelerate it.
Job done.

Ah, finally got it working, turned out i was transforming it in the wrong place, and i don’t need the other control after all :slight_smile:
Thanks everyone!!