I have a custom collision method
[java]
public void collision(PhysicsCollisionEvent event) {
if (event.getNodeA() == null || event.getNodeB() == null) return;
if (event.getNodeA().getName().equals(“playerNode”)
&& event.getNodeB().getName().equals(“Waypoint”)) {
if (collisionSentinel == 0) {
progressWaypoint();
}
} else if (event.getNodeB().getName().equals(“playerNode”)
&& event.getNodeA().getName().equals(“Waypoint”)) {
if (collisionSentinel == 0) {
progressWaypoint();
}
}
public void progressWaypoint() {
System.out.println(waypointCount);
if (waypointCount == 0) {
rootNode.attachChild(box);
boxa.setPhysicsLocation(new Vector3f(2,2,2));
waypointCount = 1;
} else if (waypointCount == 1) {
box.setPhysicsLocation(new Vector3f(20,2,2));
waypointCount = 2;
} else if (waypointCount == 2) {
box.setPhysicsLocation(new Vector3f(40,2,2));
waypointCount = 3;
} else if (waypointCount == 3) {
box.setPhysicsLocation(new Vector3f(60,2,2));
waypointCount = 4;
} else if (waypointCount == 4) {
rootNode.detachChild(box);
waypointCount = 5;
}
}
}[/java]
I am trying to get my player character to go to a “waypoint” and upon collision make the waypoint appear further down the path. Instead, what happens is it appears that the collision method is invoking the progressWaypoint() method so fast that the waypointCount cycles very quickly and the “waypoint” box is detached from the rootNode immediately.
I have tried testing with simpler progressWaypoint() method, just moving the waypoint once and it works, but the progressWaypoint() was called multiple times before moving the waypoint.
It feels like the collision listener is executing the collision method faster than the setPhysicsLocation is able to move the object away.
What is wrong with my code?