# Get the good rotation of spatial after put them on a path

hi everyone,

I have a very small problem.

When I add a spatial on a path with a motionControl (MotionEvent), this spatial have a local rotation.

This local rotation is not aligned with the path and this is normal, when i active the motion (= motionControl.play() )
the spatial rotation is aligned with the tangent of the curve of the path.

So I want to rotate my spatial (in order to align it with the tangent of the curve of the path) just after put them in the path. But i dont find how rotate my spatial corecty with a " mySpatial.setLocalRotation(vector or quaterinon); " methode.

If my explanation is not understandable i can do a sketch.

you can maybe do a sketch, but i think i understand what you mean. I’ll try to re-explain it.

Your spatial is moving along a path, and when the “road” turn, the spatial turn too, and this is normal. Hey, even if i don’t describe well the reason why the spatial has its rotation changed, the fact is, it has its rotation changed and it’s normal.

Ok, on the top of that, you want to be able to move your direction spatial with a certain angle. The problem is, when you SET the rotation, it just cancel the “normal” rotation, the rotation created by the movement on the path.

To solve this problem (if it’s the good problem i described) you have 2 choice.

1. you can decide to ADD a rotation to the current value, instead of SET it. To add a quaternion to an other, you can use mult (if i am correct, i am not sure). Of course, once you get the result (oldRotation * smallAddToTheRotation), you’ll have to set it (just like you CAN’T do getLocalTranslation.add(something) to move your spatial, you need to do setLocalTranslation somewhere). If you go that way, you don’t need to “understand” how the spatial is now directed (not use of that word, my english is bad, i am tired after a day of more than 14 hour of cleaning/painting/sawing/etc.), you only need to mult the old value with your new “small add”. However, this has some drawback.
2. If you already have somewhere the “absolute rotation you want for your spatial”, you will not like this idea of “adding value to the current one”. So, you can have a look at the method “inverse” in the quaternion. I am not absolutly sure about it, but you could maybe each frame mult the current rotation with the inverse of your previous “absolute rotation”, then mult it with your new “absolute rotation”. The idea is : remove what you changed before, then change it again to have what you want. Do this each frame. In this case, the rotation of the spatial can change because of the path, you’ll not “erase” these modifications.

Are you saying that you want the spatial properly oriented to the path when you first put it on the path? So that it doesn’t snap as soon as it starts moving? Or are you asking something else?

If that’s what you are asking, and making some other assumptions:

``````  <blockquote><a href="http://hub.jmonkeyengine.org/members/pspeed/" rel="nofollow">@pspeed</a> said:
``````

Are you saying that you want the spatial properly oriented to the path when you first put it on the path?

it’s exactly that.
this sketch show what i have an what i want to do.
http://demo.ovh.eu/fr/9f4fda20d7b9a0e960d7bd13d940390b/

``````    this.metro = assetManager.loadModel("Models\\cube\\test4.j3o");
this.metro.scale(1f, 1f, 1f);
this.metro.setLocalTranslation(-0f, 0f, 0.0f);
this.metroNode = new Node("metronode");
this.metroNode.setLocalTranslation(-50, 0f, 0f);
this.metroNode.attachChild(this.metro);
rootNode.attachChild(this.metroNode);

//animation metro
motionControl = new MotionEvent(metroNode,path);
motionControl.setDirectionType(MotionEvent.Direction.PathAndRotation);
motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y));
motionControl.setInitialDuration(10f);
motionControl.setSpeed(0.4f);
motionControl.setTime(position);
motionControl.setLoopMode(LoopMode.Loop);
``````

just after this code i want to add something like

``````      this.metro.setLocalRotation(myQuaternion);
``````

but i don’t know what is the value of " myQuaternion " in order do spatial properly oriented on the path.
After I execute " motionControl.play(); " i have no problem: all work corectly.