Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
3 registered members (TedMar, AndrewAMD, fairtrader), 578 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Chase Cam #137038
06/18/07 16:21
06/18/07 16:21
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
I'm developing a small "Flight Simulator" totally in C-Script, and the "physics" work just great. What I can't figure out is how to do a chase camera. I've tried tons of options, such as vec_for_angle, vec_to_angle,vec_add, vec_for_vertex, and vec_sub.

Here's what I have so far:

Code:

vec_set(camera.x,plane.x);
vec_set(camera.y,plane.y);
vec_set(camera.z,plane.z);



It follows the plane just the way I want, except for the fact that it's in the direct center.

So, what I want it to do is follow the plane's movements just like it does now, only about 250 quants behind the plane.

Any ideas? (and yes, I checked through the manual for anything that could help me, but to no avail.)

Last edited by MrCode; 06/18/07 16:23.

Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: Chase Cam [Re: MrCode] #137039
06/18/07 17:02
06/18/07 17:02
Joined: Nov 2005
Posts: 1,007
jigalypuff Offline
Serious User
jigalypuff  Offline
Serious User

Joined: Nov 2005
Posts: 1,007
camera.pan = my.pan; // keep the same pan with the player
camera.tilt = -5; // and look a bit downwards
try that in your player action, i would also reccomend looking through the aums, there are quite a few camera scripts in there.


Why does everyone like dolphins? Never trust a species which smiles all the time!
Re: Chase Cam [Re: jigalypuff] #137040
06/18/07 17:25
06/18/07 17:25
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
var camOffset[3] = -100, 50, 0;
var camAngle[3] = 0, -10, 0;

...

vec_set(camera.x, camOffset);
vec_rotate(camera.x, camera.pan);
vec_add(camera.x, plane.x);
vec_set(camera.pan, plane.pan);
ang_rotate(camera.pan, camAngle);


xXxGuitar511
- Programmer
Re: Chase Cam [Re: xXxGuitar511] #137041
06/18/07 19:31
06/18/07 19:31
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
Thanks, this works great!

But... I don't want the camera to match the plane's roll.

I'll keep tweaking it and see what I get,

EDIT: Ok, I made it center on the roll axis, now what I want to do is make it so that the camera is "loose", and comes back when motion has stopped.

For instance, when you pitch up, the camera stays pretty much where it is, but when you stop, the camera tilts to whatever angle the plane is at.

I would also like to do this for the pan angle.

I tried this:

Code:

function gradOrient_tilt()
{
while(1)
{
if(camAngle.tilt<= 0)
{
camAngle.tilt+= 4 * time_step;
}
if(camAngle.tilt>= 0)
{
camAngle.tilt-= 4 * time_step;
}
wait(1);
}
}

function notOrient_roll()
{
while(1)
{
camAngle.roll=plane.roll * -1;
camAngle.tilt= plane.tilt * -0.5;
wait(1);
}
}



the red part, however, is causing a mathematical conflict.

The first function states that if the camera tilt angle isn't on dead center, compensate it by increments of 4. But the second one states that the camera angle MUST be equal to the tilt of the plane, no exceptions.

Any ideas?

Last edited by MrCode; 06/18/07 20:06.

Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: Chase Cam [Re: MrCode] #137042
06/18/07 21:44
06/18/07 21:44
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
you could use the direct-set method above, and store it in another vector (camera_target_pan/x). Then use a vec_lerp() to move the camera between it's current position and the target position/amgle.

var moveFactor = 50; // (0 - 100)%
vec_lerp(camera.x, camera.x, camera_target_x, moveFactor/100);
vec_lerp(camera.pan, camera.pan, camera_target_pan, moveFactor/100);


xXxGuitar511
- Programmer
Re: Chase Cam [Re: xXxGuitar511] #137043
06/18/07 22:27
06/18/07 22:27
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
err...

I don't think vec_lerp is gonna cut it. Either I'm doing it wrong, or it's outright impossible.

Sorry if I seem picky, it's just that I've never done a chase cam script before in my life.



Code:


function def_tilt()
{
while(1)
{
camPosVector.x= camAngle.x;
camPosVector.pan= camAngle.pan;
vec_lerp(camera.x,camera.x,camPosVector,moveFactor/100);
wait(1);
}
}

function notOrient_roll()
{
while(1)
{
camAngle.roll= plane.roll * -1;
camAngle.tilt= plane.tilt * -0.5;
wait(1);
}
}




Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: Chase Cam [Re: MrCode] #137044
06/18/07 22:38
06/18/07 22:38
Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
tompo Offline
User
tompo  Offline
User

Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
try this (camera behind the player with delay) and call it from player's action:
I'm using this code with c_move, c_rotate and use_axisr mode to folow my spaceship
Code:
 
var cam_ang[3]; // direction angle of the camera to the target.
var speed = 0.4; // speed of delay (play with this value)
var temp2[3]; // to follw the player
var camera_dist[3] = -55,0,20; //you know what is this ;)

function follow_camera_movement
{
proc_late();
vec_set(temp,camera_dist);
vec_rotate(temp,camera.pan);
vec_add(temp,my.x);
vec_set(camera.pan,my.pan);
vec_set(temp2,temp);
vec_sub(temp2,camera.x);
vec_scale(temp2,speed *time_step);
vec_add(camera.x,temp2);
}



Last edited by tompo; 06/18/07 22:51.
Re: Chase Cam [Re: tompo] #137045
06/18/07 23:14
06/18/07 23:14
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
er, I'm not using c_rotate.

Code:

var video_mode= 8;
var video_screen= 1;
var video_depth= 32;

var gravity;
var plane_speed;
var lift;

var camOffset[3] = -250,0, 0;
var camAngle[3] = 0,0,0;
var moveFactor= 50;
var camPosVector[3];

var mouse_sensitivity= 10;


string plane_wmb= <planemovetest.wmb>;

sound rumble_snd= <tm150.wav>;

function main()
{
level_load (plane_wmb);
wait(3);
plane_rumble();
flyer();
notOrient_roll();
def_tilt();
}

ENTITY* plane;

action my_plane
{
plane= me;
my.fat= on;
my.narrow= on;
c_setminmax(my);
while(1)
{
if(key_w== on)
{
my.tilt-= 4 * time_step;
}
if(key_s== on)
{
my.tilt+= 4 * time_step;
}
if(key_a== on)
{
my.roll-= 4 * time_step;
}
if(key_d== on)
{
my.roll+= 4 * time_step;
}
if(key_q== on)
{
my.pan+= 4 * time_step;
}
if(key_e== on)
{
my.pan-= 4 * time_step;
}
if(key_home== on)
{
plane_speed+= 1 * time_step;
c_move (my,vector(plane_speed * time_step,0,0),nullvector,glide);
}
else
{
c_move (my,vector(plane_speed * time_step,0,0),nullvector,glide);
}
if(key_end== on)
{
plane_speed-= 1 * time_step;
}
if(key_pgdn== on)
{
my.frame+= 0.1 * time_step;
if(my.frame>= 6)
{
my.frame= 6;
}
}
if(key_pgup== on)
{
my.frame-= 0.1 * time_step;
if(my.frame<= 1)
{
my.frame= 1;
}
}
c_move (my,nullvector,vector(0,0,-gravity * time_step),glide);
vec_set(camera.x, camOffset);
vec_rotate(camera.x, camera.pan);
vec_add(camera.x, plane.x);
vec_set(camera.pan, plane.pan);
ang_rotate(camera.pan, camAngle.pan);
wait(1);
}
}

function plane_rumble()
{
ent_playloop (plane,rumble_snd,1000);
}

function wings()
{
while(1)
{
lift= plane_speed * 0.1;
wait(1);
}
}

function flaps()
{
while(1)
{
lift= plane.frame + 0.1;
wait(1);
}
}

function flyer()
{
wings();
flaps();
while(1)
{
gravity= 15 - lift;
wait(1);
}
}

function def_tilt()
{
while(1)
{
camPosVector.x= camAngle.x;
camPosVector.tilt= camAngle.tilt;
wait(1);
}
}

function notOrient_roll()
{
while(1)
{
camAngle.roll= plane.roll * -1;
camAngle.tilt= plane.tilt * -0.5;
wait(1);
}
}



I'm not keeping the flight code a secret, as the flight physics calculations aren't really all that complex.

So, can I do it without c_rotate and use_axisr?


Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: Chase Cam [Re: MrCode] #137046
06/19/07 20:38
06/19/07 20:38
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
ok, I converted the orientation code to c_rotate with USE_AXISR (works a lot better, too! ):

Code:

action my_plane
{
plane= me;
my.fat= on;
my.narrow= on;
c_setminmax(my);
while(1)
{
if(key_w== on)
{
c_rotate(my,vector(0,-4 * time_step,0),USE_AXISR);
}
if(key_s== on)
{
c_rotate(my,vector(0,4 * time_step,0),USE_AXISR);
}
if(key_a== on)
{
c_rotate(my,vector(0,0,-4 * time_step),USE_AXISR);
}
if(key_d== on)
{
c_rotate(my,vector(0,0,4 * time_step),USE_AXISR);
}
if(key_q== on)
{
c_rotate(my,vector(4 * time_step,0,0),USE_AXISR);
}
if(key_e== on)
{
c_rotate(my,vector(-4 * time_step,0,0),USE_AXISR);
}
if(key_home== on)
{
plane_speed+= 1 * time_step;
c_move (my,vector(plane_speed * time_step,0,0),nullvector,glide);
}
else
{
c_move (my,vector(plane_speed * time_step,0,0),nullvector,glide);
}
if(key_end== on)
{
plane_speed-= 1 * time_step;
}
if(key_pgdn== on)
{
my.frame+= 0.1 * time_step;
if(my.frame>= 6)
{
my.frame= 6;
}
}
if(key_pgup== on)
{
my.frame-= 0.1 * time_step;
if(my.frame<= 1)
{
my.frame= 1;
}
}
c_move (my,nullvector,vector(0,0,-gravity * time_step),glide);
vec_set(camera.x, camOffset);
vec_rotate(camera.x, camera.pan);
vec_add(camera.x, plane.x);
vec_set(camera.pan, plane.pan);
ang_rotate(camera.pan, camAngle.pan);
wait(1);
}
}



Now how exactly would i go about doing the chase cam like this? Because now, the current camera looks wierd when I go into a banked turn.

Last edited by MrCode; 06/19/07 20:39.

Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: Chase Cam [Re: MrCode] #137047
06/20/07 09:36
06/20/07 09:36
Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
tompo Offline
User
tompo  Offline
User

Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
Now try to change camera code to this one what I've wrote
Looks and works good for me
BTW: My english is not good enough What does it mean "banked turn"

Last edited by tompo; 06/20/07 09:38.

Never say never.
Page 1 of 2 1 2

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

Gamestudio download | chip programmers | 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