Orienting a Spatial to face a Ray after a collision?

Hi,



I just decided to redo some Java and I start with Jmonkey that seems really promissing.

I’m doing the tutorial one by one and I adapt things to my tastes but I encounter a problem.

I want a model loaded with the assetManager to face the camera after a colision has been detected with a Ray.

(I’m at the picking tutorial)

I get the collision detected, but can’t find the good orientation.

In fact I’m lost with Quatornion, Matrix3f and Float3f structures and don’t find a way to face a direction with simple world coordinates.

Maybe it’s more a Math problem, but even that, I don’t know what tools to use.

Any help will be appreciated.

There is a function called lookAt to help you doing that. Try something like this:

[java]clickableNode.lookAt(cam.getLocation());[/java]

Not much math involved :wink:

A helpful start with math: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:math_for_dummies

after that you should be able to move rotate and scale vectors to whereever you want :slight_smile:

Thank you guys for the fast answers :wink:



I’ll look at both solutions. lookAt already works! but I need to understand more the Math involved to continue my project, and the nice reading provided will be of a good help :wink:



Thanks again!