Hi, this is a problem that is really getting me stuck.
Here's the thing, imagine a sphere inside of a tube. When the sphere hits the inside surface of the tube, I want it to move in a new direction that would not cause another collision with the inside surface. In other words, how do I make an object such as a sphere choose a different direction/ move in a different direction that will not make it to collide with the inside surface again.
This is what i'm using to make the sphere move and what direction it's moving in.
This helps a bit, but I don't want the ball to necessarily travel in the normal direction. It will be a random direction as shown in my first post, but with any direction that would cause a direct collision with the inside surface be eliminated.
If you know the normal of the triangle, doesn't that mean that you know which directions will be viable? (nearly 90 degrees in any direction from the normal). And then pick a random direction within those limits.
Thanks for the replies guys. But since I'm still fairly new to JME, I'm not sure how to use the rays. LIke what code do I need to cast a ray in a random direction and see if the ray hits something.
public static void main(String[] args) {
TestRayPathfinding game = new TestRayPathfinding();
game.setConfigShowMode(ConfigShowMode.AlwaysShow);
game.start();
}
@Override
public void update(float time) {
Ray ray = new Ray(obj.getLocalTranslation().clone(), obj.getLocalRotation().getRotationColumn(2).clone());
PickResults results = new BoundingPickResults();
results.setCheckDistance(true);
scene.findPick(ray, results);
System.out.println("");
for(int i = 0; i < results.getNumber(); i++) {
if (results.getPickData(i).getTargetMesh() == obj) {
// we need to ignore when the ray hits the sphere itself
continue;
}
System.out.println("result: " +i +" " +results.getPickData(i).getTargetMesh().getName() +" ; " + " distance: " +results.getPickData(i).getDistance());
if (results.getPickData(i).getDistance() < 7) {
/* Danger !! */
obj.getLocalRotation().multLocal(new Quaternion().fromAngleAxis(FastMath.DEG_TO_RAD*turnspeed*time, Vector3f.UNIT_Y));
}
}
}
}
When picking, you need to be careful what you hit with the ray.
In my example, i ignored hits to my own sphere with:
if (results.getPickData(i).getTargetMesh() == obj) {
// we need to ignore when the ray hits the sphere itself
continue;
}
Ah right and if your sphere is inside another geometry, you need to use TrianglePickResults.
In my example i used BoundingPickResults for simplicity, since i just wanted simple checks.