Hi all!
How to get a contact point of physic’s Ray which collides with a spatial? I can get only a spatial which is collided.
[java] List<PhysicsRayTestResult> rayTest = bulletAppState.getPhysicsSpace().rayTest(bullet.getLocalTranslation().clone(), bullet.getLocalTranslation().add(bullet.getLocalRotation().mult(Vector3f.UNIT_Z).normalizeLocal().mult(bulletLength)));
if (rayTest.size() > 0) {
PhysicsRayTestResult getObject = rayTest.get(0);
PhysicsCollisionObject collisionObject = getObject.getCollisionObject();
Spatial sp = (Spatial) collisionObject.getUserObject();
System.out.println(sp); // collided spatial
}
}[/java]
THANKS!
With all the other info on the CollisionEvent? getLocalPointA, distance etc…
1 Like
OK, i get you.
Can i register PhysicsCollisionEvent for every bullet? For example, if i have 500 bullets in a scene, so i’ll get 500 registered PhysicsCollisionEvent objects in the physicSpace().
Also, if you want to know how far down the “ray” your contact was use hitFraction.
Here is a proposed javadoc change that includes normens explanation of hitFraction
http://hub.jmonkeyengine.org/groups/contribution-depot-jme3/forum/topic/hit-fraction-javadoc/
1 Like
You get lots more collision events even… But they are reused, thats why you have to read the values in the callback.