1 registered members (AndrewAMD),
1,089
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
FPS camera movement
#458494
03/15/16 14:47
03/15/16 14:47
|
Joined: Nov 2009
Posts: 201
Logitek
OP
Member
|
OP
Member
Joined: Nov 2009
Posts: 201
|
Hi everybody, another day, another question 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: camera.pan -= mouse_force.x * mousesensitivity; camera.tilt -= mouse_force.y * mousesensitivity;
I have also tried different ways: camera.pan -= mouse_force.x * mousesensitivity * time_step; camera.tilt -= mouse_force.y * mousesensitivity * time_step;
or 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.
|
|
|
Re: FPS camera movement
[Re: Logitek]
#458496
03/15/16 15:03
03/15/16 15:03
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Hi. This is what I do for the camera movement:
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
|
|
|
Re: FPS camera movement
[Re: 3run]
#458497
03/15/16 16:30
03/15/16 16:30
|
Joined: Nov 2009
Posts: 201
Logitek
OP
Member
|
OP
Member
Joined: Nov 2009
Posts: 201
|
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 Thank you and thanks to Kartofel.
|
|
|
Re: FPS camera movement
[Re: Logitek]
#458498
03/15/16 16:37
03/15/16 16:37
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
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:
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.
Last edited by 3run; 03/15/16 16:46.
|
|
|
Re: FPS camera movement
[Re: 3run]
#458500
03/15/16 17:29
03/15/16 17:29
|
Joined: Nov 2009
Posts: 201
Logitek
OP
Member
|
OP
Member
Joined: Nov 2009
Posts: 201
|
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 camera.tilt = clamp(camera.tilt - mickey.y / 6.5 * mouseSpeedFac, -90, 90); camera.tilt *= -1;
|
|
|
Re: FPS camera movement
[Re: Logitek]
#458972
04/11/16 14:17
04/11/16 14:17
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
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
|
|
|
Re: FPS camera movement
[Re: 3run]
#458973
04/11/16 15:21
04/11/16 15:21
|
Joined: Nov 2009
Posts: 201
Logitek
OP
Member
|
OP
Member
Joined: Nov 2009
Posts: 201
|
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 I will recheck my other code stuff.
|
|
|
Re: FPS camera movement
[Re: Logitek]
#458974
04/11/16 15:33
04/11/16 15:33
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Well, I use this code in all of my projects, so I would notice it. And BTW I'm talking about this example:
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
|
|
|
|