Hello, JME comunity.
I am newly in jMonkeyEngine. I read the beginer guide and looked through the forum but didn’t find similar issue. I try to do raycasting from an object. Ray casts perpendicularly from front edge of it and paralel to the floor. I don’t expect any collision but I get it in unexpectable place.
CollisionResults results = new CollisionResults();
Vector3f rayOrigin = geometry.getWorldTranslation().add(0, 0, geometrySize);
Vector3f rayDirection = rayOrigin.add(0f, 0f, 15f);
Ray ray = new Ray(rayOrigin, rayDirection);
shootables.collideWith(ray, results);
CollisionResult closestCollision = results.getClosestCollision();
if(closestCollision!=null) {
System.out.println("Ray origin: " + rayOrigin + ", Ray direction: " + rayDirection);
System.out.println("You shot " + closestCollision.getGeometry().getName() + " at " + closestCollision.getContactPoint() + “, " + closestCollision.getDistance() + " wu away.”);
}
This code returns to the console
Ray origin: (-0.0079099, -3.3326616, 2.7429307), Ray direction: (-0.0079099, -3.3326616, 17.742931)
You shot Floor at (-0.011273879, -4.75, 10.288773), 7.6777987 wu away.
Ray origin: (-0.0079099, -3.3326616, 2.7429307), Ray direction: (-0.0079099, -3.3326616, 17.742931)
You shot Floor at (-0.011273879, -4.75, 10.288773), 7.6777987 wu away.
Ray origin: (-0.0079099, -3.3326616, 2.7429307), Ray direction: (-0.0079099, -3.3326616, 17.742931)
You shot Floor at (-0.011273879, -4.75, 10.288773), 7.6777987 wu away.
Ray origin: (-0.0079099, -3.3326616, 2.7429307), Ray direction: (-0.0079099, -3.3326616, 17.742931)
You shot Floor at (-0.011273879, -4.75, 10.288773), 7.6777987 wu away.
Ray origin: (-0.0079099, -3.3326616, 2.7429307), Ray direction: (-0.0079099, -3.3326616, 17.742931)
You shot Floor at (-0.011273879, -4.75, 10.288773), 7.6777987 wu away.
Ray origin: (-0.0079099, -3.3326616, 2.7429307), Ray direction: (-0.0079099, -3.3326616, 17.742931)
You shot Floor at (-0.011273879, -4.75, 10.288773), 7.6777987 wu away.
Ray origin: (-0.0079099, -3.3326616, 2.7429307), Ray direction: (-0.0079099, -3.3326616, 17.742931)
You shot Floor at (-0.011273879, -4.75, 10.288773), 7.6777987 wu away.
Ray origin: (-0.0079099, -3.3326616, 2.7429307), Ray direction: (-0.0079099, -3.3326616, 17.742931)
You shot Floor at (-0.011273879, -4.75, 10.288773), 7.6777987 wu away.
How is it possible if the ray parallel to the floor? I don’t understand how it collides an object in point that have y =-4.75 if origin and direction has y= -3.33 ?