so to get the intersection point , the getHitFraction will return the fraction of the ray that is traced to another physical entity

and give : the intersection point

tada !!!

Code:

public Spatial doRayTest(Spatial entity, float length, Vector3f storeLocation) {
MovementControl control = entity.getControl(MovementControl.class);
Vector3f startLocation = control.getLocation();
Vector3f endLocation = startLocation.add(control.getAimDirection().normalize().multLocal(length));
List<PhysicsRayTestResult> results = getPhysicsSpace().rayTest(startLocation, endLocation);
Spatial found = null;
float dist = Float.MAX_VALUE;
for (Iterator<PhysicsRayTestResult> it = results.iterator(); it.hasNext();)
{
PhysicsRayTestResult physicsRayTestResult = it.next();
Spatial object = getEntity(physicsRayTestResult.getCollisionObject());
if (object == entity) {
continue;
}
if (physicsRayTestResult.getHitFraction() < dist) {
dist = physicsRayTestResult.getHitFraction();
if (storeLocation != null) {
FastMath.interpolateLinear(physicsRayTestResult.getHitFraction(), startLocation, endLocation, storeLocation);
}
found = object;
}
}
return found;
}

tada !!! :)

[edit] i find it silly somehow, ghostcontrol can tell if two entities overlap, but dont return any intersection point, so to me, using a raytest afterward is doing the job twice and loading the cpu twice ...