Controlling the Camera

Hi,

I’ve been going through the RoamingRalph example along with some of the ODE stuff and i’vebasically tried to create a plane, which is textured… and then have camera control coordinated by keypresses.

I initially used the method:

to move the camera, this function would simply manipulate the camera and change its position depending on the key pressed. The issue here though was that the key had to be repeatedly pressed in order to get multiple movements, and therefore any kindof camera movement was definitely not smooth.

So, i tried to take the idea from Roaming Ralph to give myself some smooth camera control:

Now this isn’t working, and when i do infact press ‘arrow_up’ the camera doesnt move. Pro-rsoft said that this is not supposed to work nicely, but i’m not entirely sure what he meant by that, or any alternative.

Any help is appreciated,

thanks.

Hmm… First of all, perhaps I’m just missing it, but where is your update task or tasks? Specifically, I don’t see anything there that checks for pressed keys and acts upon them if found.

Secondly, you don’t appear to be taking into account the time since the last update when you update your camera position, meaning that the camera’s movement speed should depend in part on the rate at which the camera methods are called.

Not quite sure i understand fully what you mean.

There a chance someone coudl suggest a code snippet on how to layout this thing?

I just want to be able to use the key sto move the camera…
thanks

Well, what do you not follow? If I know where you’re tripping up, I might manage to explain the issue better. :slight_smile:

Simply put, however, you don’t appear to be updating anything anywhere that I recall seeing - you have methods that can do that, but they don’t seem to be used.

In your current code, as I understand it, when a key is pressed, a variable is set, and when a key is released the corresponding variable is unset.

This is a start, but at some point you presumably want to look at the key variables and decide on how, if at all, to move the camera, and you presumably want to keep doing this, over and over again, so that the camera continues to be moved.

Essentially, it seems to me that a gameloop would serve your purposes - this is a loop that keeps running as long as the game is running (more or less), and which handles the logic of the game. In your case, the logic is that the camera should move according to key presses, it seems.

Panda offers a feature that should be useful in this: “tasks”. For an example of that, I suggest looking at the initial tutorial in the manual (which should be accessible via a link at the top of this page), specifically the section titled “Controlling the Camera”. Their logic isn’t quite the same as yours (they want the camera to keep turning as time passes, rather than responding to the keys), but the idea of task usage is there, I believe.

The other issue that I noticed is that you seem to have your camera movement methods set up so that they have the camera move by the same amount each call. So, imagine that computer A runs at some speed, and thus manages call your movement methods at a rate of x. If computer B runs twice as fast as A, let’s sat that it then manages to call your movement methods at a rate of 2x - twice as often (a simplification, admittedly). This means that computer B should have your camera moving twice as fast as it does on computer A (roughly speaking).

A solution to this is to find out how much time has passed, and make use of that in determining how far to move the camera; if the method is called twice as often in the same time, then less time passes between calls, and the two effects effectively cancel each other out.

I’ll leave it there for now, however. :wink:

I won’t give you a code snippet, as I’m programming a game and am not giving away my code, but what I did when I ran into that exact problem involved checking for ‘w’ or ‘w-repeat’, and setting a variable and starting a task to move the character/camera. On ‘w-up’, the variable is set back and the task is removed. It’s a tadddddd more complex, but that gives you a clue at least.