Shooting Rays from Objects

Hello Good people!



I would like to present a problem I have been trying to solve.



I have a 3rd Person game where the character needs to interact with the objects. Currently, I am shooting rays from the camera direction (the only way i know)



So now i need help trying to shooting the ray from the head of the character to in the direction directly infront of the character.



This is a spinet:



Ray ray = new Ray(cam.getLocation(), cam.getDirection());

System.out.println(cam.getLocation().toString());

System.out.println(cam.getDirection().toString());

CollisionResults results = new CollisionResults();

objects.collideWith(ray, results);

for(int i = 0; i < results.size(); i++){

System.out.println(results.getCollision(i).getGeometry().getName());

if(results.getCollision(i).getGeometry().getName().startsWith(“ID”)){



Please help me with this. Thanks a load!

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:math_for_dummies

Ok, understood. Thanks

You know what position your character’s head is. You just need to know what way it is facing, probably from its rotation. Rays can be built with a location and a normalized direction. The math link normen posted will help you set that up and understand how it all works, you will also need to know where on the location of your character you want to shoot from; often just the worldTranslation of the character and worldRotation will be what you need (at least to start).