Fixed camera movement system

hi,

im trying to create a “fixed camera movement system”.

The point is that i have a node/spatial(my character) and the camera with fixed coordinates and
the player should run right, but depending on the camera view.

example:

Currently im disabling the flyCam and set camera coordinates with:

[java]
app.getCamera().setLocation(new Vector3f(-1.1f, 1.8f, -5.87f));
app.getCamera().setRotation(new Quaternion(0.07f, 0.06f, 0, 0.99f));
[/java]

then im controlling the player with:

[java]
public void update(float tpf) {
player.move(Player.moveX * tpf, Player.moveY * tpf, 0);
}
[/java]

Logically the player runs always right independent from the camera location and rotation.
I want that when the camera is on the back of the player, then he will run right and
when the camera is on front of the player, then he will run left.

I tryed that with:

[java]
public void update(float tpf) {
player.setLocalTranslation(player.localToWorld(new Vector3f(Player.moveX * tpf, Player.moveY * tpf, 0), new Vector3f(Player.moveX * tpf, Player.moveY * tpf, 0)));
}
[/java]

but it doesn’t work.

I hope you understand what I mean and understand my English.

Nobody an idea?

“it doesn’t work” does not allow us to determine what exactly is going wrong - what do you see, what did you expect to see?
To sort out whether it’s the camera in the wrong position or the player moving/facing in an unexpected direction, place something immobile in the scene that the camera should see. Something asymmetric, preferrably, so you can instantly see whether the camera angle is right.

I couldn’t see anywhere that you were actually using the camera rotation in your movement calculations. Player rotation, yes, sort of… but not camera rotation. It wasn’t clear if these are linked or not… and if they are linked then I don’t see what the issue is. Actually, that last update() is a bit dodgy since it resets the position every time instead of adding to it.

@toolforger said: "it doesn't work" does not allow us to determine what exactly is going wrong - what do you see, what did you expect to see? To sort out whether it's the camera in the wrong position or the player moving/facing in an unexpected direction, place something immobile in the scene that the camera should see. Something asymmetric, preferrably, so you can instantly see whether the camera angle is right.

I try to explain it again.
What i mean is used in most of games.

Let’s say the camera ist behind my character(a third person camera).
If i press the RIGHT button, the character moves to RIGHT and if i press the LEFT button, the cahracter moves to LEFT.
So far, so simple.
Now i’m changing the position of the camera to front of my character.
If i press now the RIGHT button, the character moves to LEFT(as seen from the camera) .

I want that the character always moves to RIGHT based on the camera view,
like the camrea system in resident evil games.

@Norwido said: I want that the character always moves to RIGHT based on the camera view, like the camrea system in resident evil games.

Then you need to move the character based on the camera direction.

Is the camera direction always determined by the player/character rotation? We haven’t really been given enough information to know why this isn’t trivial.

@pspeed said: Then you need to move the character based on the camera direction.

Is the camera direction always determined by the player/character rotation? We haven’t really been given enough information to know why this isn’t trivial.

Nope, the camera has a fixed direction, that only changes if the player runs out of it.
It’s like a observation camera and the player moves based on the camera.

@Norwido said: Nope, the camera has a fixed direction, that only changes if the player runs out of it. It's like a observation camera and the player moves based on the camera.

I can’t help but feel like you are in over your head if this is what trips you up.

See, logically, you want to move the player based on the camera direction. Yet nowhere in your code do you actually use the camera direction to move the player. There is a logical disconnect. How would the player ever move in the direction of the camera if the direction of the camera is never used or consulted?

Otherwise, if you want to move the player left:
player.move( camera.getLeft().mult(tpf) ); // moves the player left one unit per second

Or right:
player.move( camera.getLeft().mult(-tpf) ); // moves the player right one unit per second

http://hub.jmonkeyengine.org/javadoc/com/jme3/renderer/Camera.html#getLeft()

1 Like
@pspeed said: I can't help but feel like you are in over your head if this is what trips you up.

See, logically, you want to move the player based on the camera direction. Yet nowhere in your code do you actually use the camera direction to move the player. There is a logical disconnect. How would the player ever move in the direction of the camera if the direction of the camera is never used or consulted?

Otherwise, if you want to move the player left:
player.move( camera.getLeft().mult(tpf) ); // moves the player left one unit per second

Or right:
player.move( camera.getLeft().mult(-tpf) ); // moves the player right one unit per second

http://hub.jmonkeyengine.org/javadoc/com/jme3/renderer/Camera.html#getLeft()

I’m not using the camera direction, that was exactly my problem and i don’t know how to move my character based on the camera direction.

player.move( camera.getLeft().mult(tpf) ); // moves the player left one unit per second

was what i needed, thanks.

English isn’t my mother tongue, i’m sorry if I’ve made myself misunderstood.

The problem is solved thanks.