Can't seem to figure out this rotation

Hey guys, I’m new here, and I’m hoping you guys can give me a push to the right direction… And I hope I am using the correct forum.



So, I have a third person view game with a controlled player. I am trying to add the ability to simple turn left or right, so rotating the player model.



The issue I am having is I can only rotate approximately 45 degrees and then rotating stops(though the Vector x value continues to change). I’ve tried several different methods but each comes out with the same result, maybe someone can explain? I would greatly appreciate it :slight_smile:



Here is the most recent code I used…

Couple of things to point out, I have created a character class for the player to bind some other information.

player.getCharacter() = CharacterControl

player.getModel() = the model Node.

[java]

private AnalogListener analogListener = new AnalogListener() {

public void onAnalog(String name, float value, float tpf) {

if (name.equals(“TurnLeft”)) {

Vector3f axis = player.getCharacter().getViewDirection();

axis.x = axis.x - 2*tpf;

player.getModel().rotateUpTo(axis);

System.out.println("Speed: "+speed);

}

if (name.equals(“TurnRight”)) {

//

}

}

};

[/java]



When axis.x reaches approximately -6 or 6, that’s when the rotating becomes really slow… eventually to a stop.



Any help or suggestions will greatly be appreciated, and thanks in advance

ViewDirection is a direction vector, not a rotation…

K, I thought that was a bit weird but I made the best progress with ViewDirection…



I looked the math wiki that talked about Quaternions, spent a day trying to understand and trying the different examples… Couldn’t get any to work.



Is it abnormal for the basic rotate function on a Spatial with the CharacterControl control attached to it not rotate at all?



I mean, my current code atm is:

[java]

private AnalogListener analogListener = new AnalogListener() {

public void onAnalog(String name, float value, float tpf) {

if (name.equals(“TurnLeft”)) {

teapot.rotate(0, 2*tpf, 0);

Vector3f axis = Vector3f.UNIT_Y;

float angle = 3.14f;

Quaternion rot = player.getModel().getLocalRotation().fromAngleAxis(angle, axis);

player.getModel().rotate(rot);

}

}

}

[/java]



My teapot does rotate, but my player does not even budge.

If you want to rotate a direction vector around its origin with a Quaternion, use myQuaternion.multLocal(myVector).

Thanks I got it :slight_smile:



For those who had a similar issue with the graphic portion… here is what I did



[java]

Vector3f compass = player.getCharacter().getViewDirection();

Quaternion rot = player.getModel().getLocalRotation().fromAngleAxis(2tpf, compass.UNIT_Y);

rot.multLocal(compass);

player.getModel().rotate(rot);

[/java]



or -2
tpf to rotate clockwise.