I’ve another problem regarding the movement of a player. Thanks to neakor and others I can move it now, but, I want that it moves into the direction where it faces to. I can easily fetch the current Y rotation, but then i’ve to add it to a vector. How do I do this?

Below is a picture of what I mean by “adding”

The black dot is always the origin (0,0,0). I need a method that takes a two dimensional vector, adds the rotation, and outputs a two dimensional vector. To that vector will be added a Y later (using neakor’s method) and it will finally be added to my character’s position. Note that I can do those things myself, I only need to know how i “add” the rotation. I could of course use trigonometry, but I don’t wanna use a lot of math. Does jME have any built in functions for this?

some how i dont really get what u r trying to do here.

so ur player moves to a position and while moving it also faces that direction, is this what u r trying to do?

u can always get the direction of movment or the destination of the movement then use lookAt method to first rotate the player toward the destination.

then just move the player to the destination through localtranslation addition. or maybe u can just jump it there. whatever way u want XD

Mathematically it's quite easy to do this, e.g. with polar coordinates (http://mathworld.wolfram.com/PolarCoordinates.html) :

• convert your 2d-vector from x-y-coordinates to polar coordinates (formula (3) and (4), but watch for division by zero)
• convert the new polar coordinates back (formula (1) and (2))

However, like neakor I doubt that you really have to do this. The rotation of a node is hold in a quaternion (http://mathworld.wolfram.com/Quaternion.html - but you don't have to know this to use them) for some good reasons, and the Quaternion class in jME contains everything you need, and you can access this quaternion with getLocalRotation(). Of course, you can also use lookAt() as convenience method.

I believe we are misunderstanding each other. So I'll be very clear, all right?

Sigh…

I have such a nice thingy in my game. It's called a player character. It can move throughout the world. People can control it by pressing the arrow keys. If they press the up key, it will move forward. If they press the down key, it'll move backward. If they press the right or the left key, it will rotate right and left, respectively. Can you still follow? Good. Now, I want, whenever someone moves their character forward, it moves in the direction it's facing. If I just add a vector (0,0,1), it will always move forward, regardless to which destination it's facing.

Owkey, now, I've such a wonderful method called move(). It takes a X and a Z coordinate. It adds those to the X and Z translation of the character, respectively. Now I want that if, say, the character has to move (0,1) and it's currently rotated at 30

theres no built in method to do that~

That means I'll have to use sine and cosine. Anyways, thanks for the help.

I've still a question: does 0 Y rotation mean it's pointed towards the X or the Z axis?

Havent tested this but this is how

I think i'll stick with sine and cosine  ;). Just found a neat application that visualizes the sine and cosine, so that makes life easier for me. Still the same question: does 0 Y rotation mean it's oriented to the X or the Z axis?

SeySayux said:

Found it

Didn't read this closely enough I'm sure, but I usually take the Quaternion rotation of my character and multiply a Vector against it the represents the unrotated direction my character would normally face.  The result is a Vector representing the current facing of the character.

SeySayux said:

I've still a question: does 0 Y rotation mean it's pointed towards the X or the Z axis?

it means lie down :D

if u use lookAt method. the y coordinate is the up vector in most cases. and 0 y means lying down~

and btw, i suggest u try it out. its really funny seeing ur player run to a position then lie down right there :D
neakor said:

SeySayux said:

I've still a question: does 0 Y rotation mean it's pointed towards the X or the Z axis?

it means lie down :D

if u use lookAt method. the y coordinate is the up vector in most cases. and 0 y means lying down~

and btw, i suggest u try it out. its really funny seeing ur player run to a position then lie down right there :D

That's impossible. The Y axis goes positive up, so that means if you rotate around it, it cannot lie down. I think you've been using 3ds too much (like me). It can only point either to the front (Z) or the right (X).

em…just try it ull know.

i was playing around with my player with lookAt method. so i know~ its pretty funny

Found it  :D.

By default, it's rotated to the Z axis. Maybe this can be useful for you too.

renanse said:

Didn't read this closely enough I'm sure, but I usually take the Quaternion rotation of my character and multiply a Vector against it the represents the unrotated direction my character would normally face.  The result is a Vector representing the current facing of the character.

So you mean...

```Quaternion q = player.getLocalRotation(); q.mult(movement);```

And then I've got the rotated version?

just a side note: 3D-Coordinate-System is not standardised. In Switzerland (where I come from) for example the Z-Axis goes positive up (which I think is quite stupid). So I'd suggest in a discussion related to Coordinate Systems one should define the grid first  8)

florian.privat said:

just a side note: 3D-Coordinate-System is *not* standardised. In Switzerland (where I come from) for example the Z-Axis goes positive up (which I think is quite stupid). So I'd suggest in a discussion related to Coordinate Systems one should define the grid first

…which I think it's much better (Y-Up) (just a personal opinion, please no opinion-war in the thread now  )

florian.privat said:

...which I think it's much better (Y-Up) (just a personal opinion, please no opinion-war in the thread now