Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,633 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Smooth Camera Movement #380136
08/13/11 10:33
08/13/11 10:33
Joined: Apr 2008
Posts: 144
Germany | Niedersachsen (Lower...
Roxas Offline OP
Member
Roxas  Offline 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.



Code:
// ...

// 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] #380139
08/13/11 10:46
08/13/11 10:46
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
The way to do so is this:
- don't "place" the camera directly at the positions
- write a seperate routine for the position
- let the camera follow this position with vec_lerp to let her move slowlier and slowlier when it reaches the position for the moving vector and angle.

Re: Smooth Camera Movement [Re: Pappenheimer] #380148
08/13/11 12:08
08/13/11 12:08
Joined: Apr 2008
Posts: 144
Germany | Niedersachsen (Lower...
Roxas Offline OP
Member
Roxas  Offline OP
Member

Joined: Apr 2008
Posts: 144
Germany | Niedersachsen (Lower...
Thanks for the quick reply Pappenheimer.

I took a look at the example in the manual for "vec_lerp" but i don't quite get it how it is working after all.

I also tried some examples from the forum but I think i don't use it correctly. Could you give me a quick example on how to use this function properly maybe?
Since I'm german and I suppose you too you may explain it in german as well, but for the sake of the forum I would like to stick to english, so that everyone is able to learn something.

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 Offline
Senior Expert
Quad  Offline
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 Offline OP
Member
Roxas  Offline 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:

Code:
// ...
// 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.
Re: Smooth Camera Movement [Re: Roxas] #380166
08/13/11 21:57
08/13/11 21:57
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
did you try to set a constant lerp factor?

Re: Smooth Camera Movement [Re: Pappenheimer] #380175
08/14/11 08:10
08/14/11 08:10
Joined: Apr 2008
Posts: 144
Germany | Niedersachsen (Lower...
Roxas Offline OP
Member
Roxas  Offline OP
Member

Joined: Apr 2008
Posts: 144
Germany | Niedersachsen (Lower...
Well I tried several ways to control the camera movement but when I try to set a constant lerp factor the camera won't move at all. And since i want it to move I don't see another way. Or do I have to move the camera itself?

Roxas~

Re: Smooth Camera Movement [Re: Roxas] #380181
08/14/11 11:24
08/14/11 11:24
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
As far as I can see from your code, the desirded position isn't moving, right?

When the camera reached the desired position, it won't move, for sure, because it only moves when it didn't already reach the desired position.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1