How to remember results from a collision for later use

Hey there, been following the tutorial examples and they are fantastic! good work guys :slight_smile:

So I’ve successfully followed the picking tutorial and am able to click objects on my screen and report their name and the collision point (between the ray and collided object). I’ve even made some custom models and imported them into the scene for use…

I’m following the exercises in the picking tutorial and now trying to manipulate the object I have clicked on. At this point I would like to be able to reference the node of the object that my mouseRay is colliding with and save that information so that I can manipulate it in several different ways. Ex: for the selected object- the ‘m’ key will allow the object to loop-move to a location slowly, and the j key will allow it to teleport to a location instantly.

How do I reference the actual node of the object with which my ray is colliding with?

Using: [java]String hit = results.getCollision(i).getGeometry().getName();[/java] I can reference the name of the geometry that I am colliding with, but how can I store that item’s node for interaction?

Here is some psuedo-code for what I wish to be able to do if this helps any:

selectedItem = results.getCollision(i).getNode();


on mouse press, selectedItem.setLocalTranslation(newx,newy,newz);


Its probably a parent of the collision Geometry, so you can check you way through getParent() until you find the specific parent node you are looking for.

thanks for the quick reply :slight_smile: so how would i store and then reference the result of getParent()?

something like: results of getParent() = object selectionObject ?

Am I thinking this through incorrectly?


Spatial parent=spatial.getParent();

while(parent!=null && !parent.getName().equals("NameIAmLookingFor")){




System.out.println("I found it!");



1 Like

Thanks so much! I will work this in to what I am doing and see if I can’t get it working


Here is the code I have from the hello picking tutorial in case anybody else new was wondering the same question.

It scales the picked object’s node up by 10% each click

[java] for (int i = 0; i < results.size(); i++)


float dist = results.getCollision(i).getDistance();

Vector3f pt = results.getCollision(i).getContactPoint();

String hit = results.getCollision(i).getGeometry().getName();

System.out.println("* Collision #" + i);

System.out.println(" You shot " + hit + " at " + pt + “, " +dist + " units away.”);


if (results.size() > 0)


CollisionResult closest = results.getClosestCollision();



Spatial papa = results.getClosestCollision().getGeometry().getParent();

System.out.println("Found: " + papa);