Hello! So, another problem just popped up for me … :explode: It’s probably easy to solve, but I’ve been searching for an answer and trying out my own stuff but I think I need some help! So, I was wondering, I use a ray collision to find intersections when you click… as you’d do…
CollisionResults results = new CollisionResults();
Ray ray = new Ray(cam.getLocation(), cam.getDirection());
String nameHit = results.getClosestCollision().getName();
This works perfectly for geometries that are just added through code, but not for Spatials using imported assets… so, how would I make it recognise spatials as well? They all have a RigidBodyControl, maybe that helps? Thanks!
what doesn't work? It will give you back the geometry that collided, maybe you want the parent or something?
You can also do a PhysicsRayCast, which will use the collision shape instead.
Ah, I should have been more specific. The name of the geometry is simply “cylinder1” despite the fact that I set the name of the spatial to “beer can”… how do I set the name of whatever the ray collides with?
Well everything derives from the Node class, so it’s difficult to distinguish between objects like that. It was a bad example tbh. An alternative approach would be to check the name instead of the type:
you have that backwards jayfelle,. everything derives from Spatial, not Node. Node is a subclass of spatial.
but yes the easiest way to do is is to traverse upwards and check for the name of the node youre looking for.
another way to do it is to look for userdata or controls attached, for instance if you wanted to play a “hit” animation on a character, then traverse up until you find AnimControl. it just depends on what kind of data youre searching for.