How to find out if Spatial is inside certain area?

What process would I go about to determine if a Spatial or other object was inside the volume of another object? Like being underwater, or inside a certain room, etc.

the fastest way i guess is to consider sphere volumes, so it has a center (vector3f) and a radius (float).

To check is an object is inside, compute the length of the difference between the position of the player and the center and compare it to the radius.



If you want more complex shapes like cubes, it’s a bit more complicated.



But there are bounding volumes in jME that could be used for this i guess. Look at boundingSphere and BoundingBox, there are intersect methods for several primitives that returns if something intersect or is inside the bounding volume.

what nehon said.

A simplest thing you can try is put this in an update loop:

if(roomSpaital.getWorldBound().intersects(PlayerSpatial.getWorldBound()))



This is only really accurate for box shaped spatials. It will create a boundingBox based on the largest width, height and depth of the spatial.

That’ll work, thanks!