FPS camera movement

Posted By: Logitek

FPS camera movement - 03/15/16 14:47

Hi everybody, another day, another question smile

There were already similar questions on this forum, but I didn't find a real solution. So I will try to ask here.

I have tried to make the FPS camera movement more smoother. If you move the mouse slowly, it is smooth, but if you move the mouse faster to look around, it is not that smooth, often also jittery or it is stuttering. Maybe this is the wrong word for it. It looks like that it is not smooth. FPS is 60. So that is not the problem. And the camera movement instructions are in a proc late function.

I think everybody knows that code already, because it seems to be standard in 3dgs:

Quote:

camera.pan -= mouse_force.x * mousesensitivity;
camera.tilt -= mouse_force.y * mousesensitivity;


I have also tried different ways:

Quote:

camera.pan -= mouse_force.x * mousesensitivity * time_step;
camera.tilt -= mouse_force.y * mousesensitivity * time_step;


or

Quote:

camera.pan -= mouse_force.x * maxv(mousesensitivity, 0.001);
camera.tilt -= mouse_force.y * maxv(mousesensitivity, 0.001);


also with mickey. But it was not the right thing.
The result were better with mouse_force but not perfect.

So maybe anyone else has already found out a better way, or an idea to make the movement of the FPS cam smoother.

Thanks.
Posted By: 3run

Re: FPS camera movement - 03/15/16 15:03

Hi.

This is what I do for the camera movement:
Code:
var mouseSpeedFac = 1;

camera.pan = cycle(camera.pan - mickey.x / 6.5 * mouseSpeedFac, 0, 360);
camera.tilt = clamp(camera.tilt - mickey.y / 6.5 * mouseSpeedFac, -90, 90);

And it works perfectly for me. I remember this code was given to me by Kartofel, so all credit goes to him. Btw, I would avoid using 'proc_late' for camera, just call it right at the end of the player's movement code's loop (right before 'wait(1)').



Greets
Posted By: Logitek

Re: FPS camera movement - 03/15/16 16:30

Hi, I have made a quick test.
And it seems that this is really the best solution!
I will make some further tests to get sure, because I can't believe that laugh

Thank you and thanks to Kartofel.
Posted By: 3run

Re: FPS camera movement - 03/15/16 16:37

Quote:
Also don't use 'time_step' with 'mickey' as it's already there.
I don't remember where I heard this, thought it might be wrong (cause example in the manual uses 'time_step'). Anyway I'm glad to help!


Just made a small test, take a look at this code:
Code:
void main(){
	fps_max = 60;
	level_load("");
	wait(3);
	
	ent_create(CUBE_MDL, vector(200, 50, 0), NULL);
	ent_create(CUBE_MDL, vector(200, 0, 0), NULL);
	ent_create(CUBE_MDL, vector(200, -50, 0), NULL);

	while(1){
		
		fps_max = 60;
		if(mouse_right){
			fps_max = 30;
		}
		if(mouse_left){
			fps_max = 512;
		}
		DEBUG_VAR(fps_max, 10);
		
		camera.pan -= mickey.x * time_step; // try without time_step too
		
		wait(1);
	}
}

It can show why it's better to do not use 'time_step' but to allow player to adjust "mouseSpeedFac".


Best regards.
Posted By: Logitek

Re: FPS camera movement - 03/15/16 17:29

Thanks for the information. Yes, I know mickey is already using time_step. I read that anywhere in the past. After some further tests I can say, it is working great. Better than I thought. For vertical invert I have used

Quote:

camera.tilt = clamp(camera.tilt - mickey.y / 6.5 * mouseSpeedFac, -90, 90);
camera.tilt *= -1;
Posted By: Logitek

Re: FPS camera movement - 04/11/16 10:30

Hello. After a lot of tests I have seen that it is running really good with a high framerate. But if the framerate is for example only 30 it is not that smooth anymore. Of course, 30 fps is only the half of 60, that's true. But if you look at tripe A games, they have also no problem with a smooth camera movement at 30 fps. What is their secret? I know, Gamestudio is using the windows mouse driver, as far as I know, but maybe their is another trick, another algorithm?
Posted By: 3run

Re: FPS camera movement - 04/11/16 14:17

Originally Posted By: Logitek
Hello. After a lot of tests I have seen that it is running really good with a high framerate. But if the framerate is for example only 30 it is not that smooth anymore. Of course, 30 fps is only the half of 60, that's true. But if you look at tripe A games, they have also no problem with a smooth camera movement at 30 fps. What is their secret? I know, Gamestudio is using the windows mouse driver, as far as I know, but maybe their is another trick, another algorithm?
Hi!

It work very smooth for me, independent to framerate (you are doing probably something wrong). I don't have any visual differences between 30-60 fps (as same as the example I posted above).


Best regards
Posted By: Logitek

Re: FPS camera movement - 04/11/16 15:21

Hello. I know, it is the best camera code.

I have tested your example too. And I have tested it now again.

But instead of

camera.pan -= mickey.x;

with the line:

camera.pan = cycle(camera.pan - mickey.x / 6.5 * mouseSpeedFac, 0, 360);


The mouseSpeedFac var is 1

And it does not look that smooth at 30 fps. It is hard to see if you use only the 3 box models. But maybe only my eyes are confuse wink I will recheck my other code stuff.
Posted By: 3run

Re: FPS camera movement - 04/11/16 15:33

Well, I use this code in all of my projects, so I would notice it. And BTW I'm talking about this example:
Code:
var mouseSpeedFac = 1;

camera.pan = cycle(camera.pan - mickey.x / 6.5 * mouseSpeedFac, 0, 360);
camera.tilt = clamp(camera.tilt - mickey.y / 6.5 * mouseSpeedFac, -90, 90);



Best regards
Posted By: Logitek

Re: FPS camera movement - 04/11/16 15:42

Well. I use this code too. Because it is the best. Maybe it is anything else in my code that is confusing my eyes. But it is also possible that it is my mouse. I will make some further tests.
Posted By: 3run

Re: FPS camera movement - 04/11/16 15:43

Originally Posted By: Logitek
Maybe it is anything else in my code that is confusing my eyes.
Make sure to call all camera stuff right at the end of the player's loop.

Greets
© 2024 lite-C Forums