Question about rotation

Hi!



I’m building a combat scene between the player 1 and the noplayer (see the image below) and I’m realy desperate!

All I need to do is to make the player 1 rotate around the nonplayer character. The player must rotate the moment the player hits the arrow keyes up and down.



PS: the keyes are working pretty well.







Thanks!

Hi renase!



I don

you have to reset diff to noPlayer location at every update since subtractLocal changes diff internaly…

Here's one way to do it - please note this code is all from the top of my head and not doublechecked.



You should be able to construct two Quaternions (or perhaps one that you inverse, but for simplicity let's use two) to represent your up and down key actions.  Something like:


        Quaternion upRotate = new Quaternion();
        upRotate.fromAngleAxis(5 * FastMath.DEG_TO_RAD, Vector3f.UNIT_Y);

        Quaternion downRotate = new Quaternion();
        downRotate.fromAngleAxis(-5 * FastMath.DEG_TO_RAD, Vector3f.UNIT_Y);



Then you can take the vector from the npc to your pc like so:

        Vector3f diff = new Vector3f(npc.getWorldTranslation());
        diff.subtractLocal(pc.getWorldTranslation());



Finally, multiply the vector by the rotation desired (based on key press), then add it back to the npc's location:

        upRotate.mult(diff, diff);
        pc.getLocalTranslation().set(npc.getWorldTranslation()).addLocal(diff);



The last line assumes that the npc and pc are not being translated by various parents, etc.  You'll have to tweak it for your situation.

Once you get it working, maybe post the actual code for that section so others can benefit.

Hi!



Still don

first of all, you need negate the direction of the diffvector, or subtract the other way around, like this:



diff = new Vector3f(TheEndOfEternity.player1.getWorldTranslation());

diff.subtractLocal(TheEndOfEternity.noPlayer.getWorldTranslation());



second, upRotate.mult(diff,diff) will trash the quaternion calculation so you need another vector for the result…or lazily do like this:



upRotate.mult(new Vector3f(diff), diff);

Yep, my bad.  some of our mult methods do and some don't.  I'll change quat in cvs to not trash the input vector.

Hi!



I make what you wrote MrCoder, but still don

Ugh, your code is not very close to what I was saying.  I'll try to look tomorrow when I can.

HI!



Sorry guy! Forget my last post…I just was looking for another way :’( …I make what you write…but my character moves in “Y” too.



public BatalhaPlayer(InputHandler input){ //contructor
   this.diff = new Vector3f(TheEndOfEternity.noPlayers.getChild(0).getWorldTranslation());
   upRotate.fromAngleAxis(5 * FastMath.DEG_TO_RAD, Vector3f.UNIT_Y);//testing
                ....
}



public void update(float tempo){
   this.diff = new Vector3f(TheEndOfEternity.noPlayers.getChild(0).getWorldTranslation());
                ........
                ........
               if (keyboard.isValidCommand("rotUp")){
      upRotate.mult(new Vector3f(diff), diff);
      diff.subtractLocal(TheEndOfEternity.players.getChild(0).getWorldTranslation());
      TheEndOfEternity.players.getChild(0).getLocalTranslation().set(TheEndOfEternity.noPlayers.getChild(0).getWorldTranslation()).addLocal(diff);
}



Hi guys!



Ok! The problem is solved! aff…Just this:



if (keyboard.isValidCommand("rotUp")){
                        
   noPlayerPosition = TheEndOfEternity.noPlayers.getChild(0).getWorldTranslation();
   noPlayerPosition.y = 0;
            
   float x = 0.01f;
   float z = 0.01f;
            
   upRotate.mult(new Vector3f(x, y, z), auxVec);
   auxVec.subtractLocal(TheEndOfEternity.players.getChild(0).getWorldTranslation());
            
   TheEndOfEternity.players.getChild(0).getLocalTranslation().set(noPlayerPosition).addLocal(auxVec);
}



PS: why this?

noPlayerPosition.y = 0;
float x = 0.01f;
float z = 0.01f;

...because when I create my "werewolf" in Blender, the meridians of the werewolf are diferent of my player...and so the Y positions on vector must be diferent(werewolf and player)...some like this:

player1.getLocalTranslation().y = 0 ->player
noPlayer.getLocalTranslation().y = 5 -> Werewolf

Thx guys and sorry again...

But I have more one question...How can I controll the speed that my charcter move around the werewolf?