Camera Looks At Mouse Pointer?

Can I make it so that my camera looks wherever I decide to point my mouse? For instance, if I start scrolling my mouse very quickly to one side, the entire screen will rotate drastically. I do not want to have to press a button to make this work. I just want it to happen. Thanks a ton!

1 Like

Yep…

suedo-code:
[java]
mouseXY.substract(centerScreenXY).normalize();
[/java]

this will give you a value of -1.0 to 1.0 for both mouse x and y.

adjust your cam direction or rotation or whatever… using deltaX above for y rotation and deltaY above for x rotation.

it’s something along those lines, anyways.

Are there any examples that you know of that have code like this?

you might want to look at ChaseCamera.java (as well all the other camera related classes like FlyByCamera) for having the camera respond to mouse input, and how to make the animation nice and smooth looking.

You might be able to take FlyByCamera code and combine it with some acceleration/dampening code from ChaseCamera to create the kind of camera you want.

You can look at the supplied cameras with jme3 and see if any of them have stuff you need. I don’t think I really understand what you are trying to achieve though.

Essentially, I want the character (and camera) to rotate by simply moving the mouse. Similar to minecraft, yes? The game I’m making is nothing like minecraft, but that element of the game will be the same. I’ll check out the other cameras, but any other ideas would be appreciated in the time being. Thanks again!

Use getDeltaX() and getDeltaY() from the mouse event (raw input listener > mouse move handler) This will give you what you need to apply the y/x rotation to the camera

@007-Winner said: Essentially, I want the character (and camera) to rotate by simply moving the mouse. Similar to minecraft, yes? The game I'm making is nothing like minecraft, but that element of the game will be the same. I'll check out the other cameras, but any other ideas would be appreciated in the time being. Thanks again!

The part we are not 100% clear on is how this is different than the normal fly cam behavior that is included with all applications by default.

Edit: also if you choose to go with the “roll your own” approach there is no need to use RawInputListeners. You can do everything with normal mouse axis triggers just like FlyCam does.

I am making a game with a third person view. The initial flycam will not do what I want it to do. However, I will try to use your suggestions to figure this out. I will post back and tell you what I find out.

You can have a look at my FirstPersonCameraControl it can easily adapted to third person.