Problem with Chasecam, Quaternion and Movement

Hello,

I have a chase camera focused on an object (such as a player). Through clickin on the camera-screen (inside the window) I’m able to move the player.

“moveDirection” is the vector i use to specify the vector my player should be moved.

[java]player.move(moveDirection);[/java]

The first vector is created by getting the screens height and width, subtracting the half of them, creating a coordinatesystem with its origo on the node the chasecam is on (the player).

Then trying to get the rotation to the currentcameraposition, then inverting that rotation so I can land the vector from the x-y of the camerascreen to land on the model in such a way that pressing directly below the playermodel will move it “towards” the camera.



[java]public void setMoveDirection(){

moveDirection.set(inputManager.getCursorPosition().getX()-(cam.getWidth()/2),0, (inputManager.getCursorPosition().getY()-(cam.getHeight()/2)));

changeHori = new Quaternion().fromAngleAxis(chaseCam.getHorizontalRotation()+FastMath.PI , Vector3f.UNIT_Y);

changeHori.inverseLocal();

changeHori.multLocal(moveDirection);

moveDirection.normalizeLocal();

}[/java]



In case what i tried to say came out wrong (im gettin sleepy >_< ), It’s an isometric view, and clicking on the screen, depending where the playermodel is, should be moving that playermodel in the desired direction. Kinda like “Diablo”, just it’s 3d so can horizontally rotate.



Any help appreciated :3

you mean that you want it to go away from the cam, but it goes toward it right?

what about multiplying the direction by -1?

Yeah, I realize now tho that the codeexample i got posted isnt the one that was “closest” to working :stuck_out_tongue: was messing around with the negatives and rotations.

But i had one rotation that “worked” in the sense that the initiated camera angle was giving me proper movement when interacting with the screen, but as soon as i’d rotate next time i tried to move the movements went very wrong, up wasnt up anymore, down wasnt down.

But notice i said “had” :stuck_out_tongue:

It was a " - " that was needed, not the position i thought it would have been , and i aint sure why still. but its a quaternion - I dont really wanna try to figure out exactly how it works, aslong as it does what i want throwing one vector in one end to get another out.



the " - " was on the chaseCam.getHorizontalRotation() - FastMath.PI



[java]public void setMoveDirection(){

moveDirection.set(inputManager.getCursorPosition().getX()-(cam.getWidth()/2),0, -((inputManager.getCursorPosition().getY()-(cam.getHeight()/2))));

changeHori = new Quaternion().fromAngleAxis(chaseCam.getHorizontalRotation()-FastMath.HALF_PI , Vector3f.UNIT_Y);

changeHori.inverseLocal();

changeHori.multLocal(moveDirection);

moveDirection.normalizeLocal();

}[/java]

Seems to work fine now even after rotating, I’m probably getting alittle offset from the vector based on the screen width and height since that isnt 1x1 but seems neglible atm. higher resolution maybe it will be worse, but this works for now <3.

Thanks nehon, it helped me :slight_smile: