|
Smooth Camera Movement
#380136
08/13/11 10:33
08/13/11 10:33
|
Joined: Apr 2008
Posts: 144 Germany | Niedersachsen (Lower...
Roxas
OP
Member
|
OP
Member
Joined: Apr 2008
Posts: 144
Germany | Niedersachsen (Lower...
|
Hey there, I've got a question about smooth camera movement~ In many games with a third person camera the camera rotates smoothly around the player. Even if you stop touching the camera buttons the movement of the camera seems to stop smoothly not abrupt. Even the Engine fly trough camera does this when you hit the 0 Button, move around and then stop pressing the arrow keys. My problem is, that every single camera code I tried doesn't offer something like this. But how do you do something like this? To specify my Problem, I am working on a role-playing game with a turn based battle system at the moment. Now i wanted to create some camera movements. For example when a Battle is going to begin the camera should move around the battlefield and show the enemies and the allies. I started with a simple circle movement around the battlefield. but the camera stops abrupt when it reaches the position where i want it to stop.
// ...
// I specify some startvalues
var camAngle = 350;
var camZoom = 600;
var camSpeed = 15;
// and set a focus for the camera
vec_set(tempFocus, camFocus);
while(camAngle > 225)
{
// this is supposed to slower the movement
camAngle -= ((camSpeed*camAngle)/1000) * time_step;
camera.z -= ((camSpeed*camAngle)/1000) * time_step;
camZoom -= ((camSpeed*camAngle)/1000) * time_step;
// i want it to move in a circle around my focus
camera.x = tempFocus.x + camZoom * cos(camAngle);
camera.y = tempFocus.y + camZoom * sin(camAngle);
// And the camera should keep its focus on the specified point
vec_set(temp, tempFocus.x);
vec_sub(temp, camera.x);
vec_to_angle(camera.pan, temp);
if(camAngle > 359){camAngle = 0;}
wait(1);
}
i'm fine with the movement itself but it should be more "smooth". heres a little reference. You'll see a camera movement right at the beginning of the video. (ca. 0:08) Final Fantasy X-2 Battle Any Ideas? thanks in advance ! Roxas~
|
|
|
Re: Smooth Camera Movement
[Re: Roxas]
#380156
08/13/11 15:37
08/13/11 15:37
|
Joined: Oct 2007
Posts: 5,211 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,211
İstanbul, Turkey
|
you should use it like this:
first calculate the position where the cameta SHOULD be if there were no smoothing to a vector( vcalc ), then use vec_lerp to calculate camera.x using the calculated position and the current position of the camera.
vec_lerp( camera.x,current position,calculated position,play with this factor value)
3333333333
|
|
|
Re: Smooth Camera Movement
[Re: Quad]
#380160
08/13/11 16:54
08/13/11 16:54
|
Joined: Apr 2008
Posts: 144 Germany | Niedersachsen (Lower...
Roxas
OP
Member
|
OP
Member
Joined: Apr 2008
Posts: 144
Germany | Niedersachsen (Lower...
|
Thanks for your reply Quad! I came up with some results now and they're looking way better then before, but i don't know if I am using it right now because I find it strange that the factor does to be SO small to obtain a decent speed for the camera movement:
// ...
// tempFocus is the position the camera's looking at
vec_set(tempFocus, camFocus);
// setting camera position and some settings
vec_set(camera.x, vector(500,0,400));
camZoom = 500;
camAngle = 350;
// desired camera position
temp.x = tempFocus.x + camZoom * cos(225);
temp.y = tempFocus.y + camZoom * sin(225);
temp.z = camera.z-150;
while(counter < 350)
{
vec_lerp(camera.x, camera.x, temp.x, camFactor);
// camera should face the focus point
vec_set(temp2, tempFocus.x);
vec_sub(temp2, camera.x);
vec_to_angle(camera.pan, temp2);
// Factor for the interpolation.
camFactor += 0.005 * time_step;
// counter to determine the length of the "camera movement"
counter ++;
wait(1);
}
Is this the right way to do it? the "effect" looks quite okay to me but well~ Thanks in advance Roxas~
Last edited by Roxas; 08/13/11 16:54.
|
|
|
|