CollisionResults results = new CollisionResults();
ray.setOrigin(cam.getLocation());
ray.setDirection(cam.getDirection());
rootNode.collideWith(ray, results);
if (results.size() > 0) {
Spatial target = (Spatial)(results.getClosestCollision().getGeometry());
if (target.getName().equals("door")) {
System.out.println(target.getControl(AnimControl.class));//.getChannel(0).setAnim("open");
System.out.println(door.getControl(AnimControl.class));
}
}
The code above shows how the target spatial, which is a spatial spatial named “door”, is being returned by the collision results.
Doing this should return an exact copy of the target Spatial right? So by that definition, the target, which is now referencing the door Spatial, should allow me to get its animation control. The weird thing is,
System.out.println(target.getControl(AnimControl.class));
prints out null, while printing out the AnimControl of the original Spatial prints out the actual AnimControl.
System.out.println(door.getControl(AnimControl.class));
I do know that there is another way to go about doing this; That it is also possible to just make the animation channel for every door in my game a global variable, and then do something like, door4channel.setAnim("open) but I think this way is a more convenient and simpler way to do it.
So would anyone know how to get the AnimControl from a CollisionResult? Thanks.