Hi, my program does something simple. You select an object clicking it, you move it dragging the mouse, and then you drop it clicking again in a location. While the object is dragged, it’s spatial is painted wireframe, as a form of feedback.
Now I want to add collisions, so you can’t drop an object where there’s already one. I know from the tutorial you have to add a PhysicsControl to the object, and you must call setPhysicsLocation() on the control instead of setLocalTranslation() on the spatial.
Currently, I have a “picked” spatial as a member of the simple application that is what I use to paint the dragged object. Now if I must use setPhysicsLocation() to move it, I must have also the control around.
Is there a way to only use one of them, and get one from the other? Or which approach do you suggest?
<cite>@nehon said:</cite>
Not sure if it's what you're looking for but you can do.
spatial.getControl(PhysicsControl.class);
and
control.getSpatial();
spatial.getControl seems like it could work. But control.getSpatial() seems not to exist, at least on RigidBodyControl.
<cite>@Empire Phoenix said:</cite>
Do you want it to block if its put somwhere wher eit should not or only to be like red wireframe for no not there?
I suggest using a ghost physic thing, it only gives you collision events, but does not actually collide.
The red wireframe when in collision would work fine, and a condition that do not let the object be dropped when collision. How does this ghost physic work? Is it like this? (I found that after writing the question).
[java]
public void collision(PhysicsCollisionEvent event) {
if ( event.getNodeA().getName().equals(“player”) ) {
final Node node = event.getNodeA();
/** … do something with the node … /
} else if ( event.getNodeB().getName().equals(“player”) ) {
final Node node = event.getNodeB();
/* … do something with the node … */
}
}
Now I’m currently thinking about using physics collisions or simple triangle collisions. And I still have to analize your answers to fully understand them.
But I think we can consider that the question is solved, because my next doubts will be about the problem. Thanks, again.