Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (dr_panther, AndrewAMD, Ayumi, TedMar), 1,033 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Chase Camera #270266
06/07/09 11:12
06/07/09 11:12
Joined: Jun 2009
Posts: 4
M
Micmac_Creations Offline OP
Guest
Micmac_Creations  Offline OP
Guest
M

Joined: Jun 2009
Posts: 4
Hey guys

I just started developing a 3d fly around game similar to Star Fox 64/Lylat wars. I am having trouble creating a 3rd person chase camera to follow the ship. The problem I am having is, that when I rotate the ship, the camera rotates, but doesn't follow behind it. So when you turn 180 Degress, the camera is in front of the ship. I know this is probably a basic error, but i can't seem to figure it out.

Thanks


Micmac Creations
Re: Chase Camera [Re: Micmac_Creations] #270269
06/07/09 11:27
06/07/09 11:27
Joined: Apr 2009
Posts: 298
Southern Oceans
KiwiBoy Offline
Member
KiwiBoy  Offline
Member

Joined: Apr 2009
Posts: 298
Southern Oceans
Heres a complete example that was working prior to this post smile

Click to reveal..
//fpsp Created by Vadim647 from his example
#include <acknex.h>
#include <default.c>

///////////////////////////////////////////////////
//**************************************************|added
#define max_cam_dist 5000;
#define min_cam_dist 10;
#define max_cam_angle 90;
#define min_cam_angle 1;

var cam_dist = 100;
var cam_angle = 1;
var cam_move[3];
var temp_var;

BMAP* crosshair_map = "cross.tga";


function bomb_event();
function move_bomb();
function follow();


STRING* bomb_mdl = "bomb.mdl";
//STRING* ring_mdl = "fogband.mdl";


FONT* arial_font = "Arial#20";
////////////////////////////////////////////////////

VECTOR temp_vec, tv;
ENTITY* fpsp;
var fpsp_10;
var my_pos[3];
var add_pan;
var add_tilt;
////////////////////////////////////////////////////

//simply comment whole panel to disengage
PANEL* my_pan =

{

layer = 15;

pos_x = 0;

pos_y = 0;

bmap = "DckWnFram2.tga"; // the frame panel

// button = 780, 0, quit2_pcx, quit1_pcx, quit2_pcx, quit_game, null, null;

flags = visible;

}



PANEL* crosshair_pan =
{
bmap = crosshair_map;
layer = 20;
pos_x = 0;
pos_y = 0;
flags = TRANSLUCENT, OVERLAY;
}

//////////////////////////////////////////////////////

function fps_player()//Vadim647
{//simple gliding algoritm for player
fpsp = me;
set(my,SHADOW);
vec_fill(my.scale_x,0.1);
c_setminmax(me);

crosshair_pan.pos_x = screen_size.x / 2 - 32; // the crosshair has 16x16 pixels
crosshair_pan.pos_y = screen_size.y / 2 - 16;
while (1)
{
set(crosshair_pan,SHOW);
my.skill1 += (key_w-key_s) * 2 * (1 + 2 * key_r);
my.skill2 += (key_a-key_d) * 2;
my.skill10 = c_trace(my.x,vector(my.x,my.y,my.z-4096),IGNORE_ME|IGNORE_PASSABLE|USE_BOX);
fpsp_10 = my.skill10;
// if (vec_length(my.skill1)>3) vec_normalize(my.skill1,2);//speed
// vec_normalize(my.skill1,vec_length(my.skill1) * 1.35);
// my.skill1 += (key_w-key_s) * 0.2;
vec_set(temp_vec,my.skill1);
vec_rotate(temp_vec,my.skill7);
vec_add(temp_vec,my.skill4);
c_move(me,nullvector,temp_vec,IGNORE_PASSABLE|GLIDE);

vec_set(camera.x,my.x);
camera.x = my.x - 30 * cos(my.pan); // ...3rdP mode 200 = distance
camera.y = my.y - 30 * sin(my.pan); // same value here
camera.z = my.z;

vec_set(camera.pan,my.skill7);
my.skill7 -= mouse_force.x;
my.skill8 += mouse_force.y;
my.pan = camera.pan;
my.tilt = camera.tilt;// * mouse_force.y;



add_pan=0;
add_tilt=0;

add_pan=minv(40*time_step,(maxv(mouse_force.x*5,-40*time_step)));
add_tilt=minv(40*time_step,(maxv(mouse_force.y*5,-40*time_step)));
if(my.roll>time_step*5){my.roll-=time_step*5;}
if(my.roll<time_step*5){my.roll+=time_step*5;}
my.roll+=add_pan;
my.roll=minv(40,(maxv(my.roll,-40)));
my.pan -= add_pan*.5;
my.tilt -= add_tilt*.5;
while(key_f < 0){wait(1);}
if(key_f ==1)
{
my.skill1 -=0.1*time_step;
if(my.skill1 <= 0)
{
my.skill1 = 0;
}
my.skill2 = 0;

}
if(my.skill1 > 3)
{
my.skill1 = 3;
}
while(key_b < 0){wait(1);}
if (key_b > 0)

{
// create the bomb 20 quants below the bird's origin
ent_create (bomb_mdl, vector(my.x, my.y, my.z - 10), move_bomb);
}
wait(1);
}
}



void main()//Vadim647
{
vec_set(sky_color,vector(192,160,128));//background color
var video_screen = 2;
video_switch(8,32,2);//used in conjunction with video_window
video_window(nullvector, vector(1024,568,0), 1, "Adapted from Vadim647 flight script");
level_load("flightTest.wmb");//load your own level here
wait(3);
ent_createlayer("scifi1b+6.tga", SKY | CUBE | VISIBLE, 0); // create the sky layer
camera.clip_far = 15000;//clipfar. If you've made too big level and it lags, reduce it
camera.clip_near = 0;//since camera can go very close to walls, we set it to 0
camera.arc = 70;//makes it look more unique wink
move_friction = 0;//gliding requires this one
ent_create("AirRaptor.mdl",vector(-2200.00,0,50),fps_player);//and finaly, create the player entity
fog_color = 1;
fps_max = 60;
camera.fog_start = 0.01 * camera.clip_far; // fog starts at 10% of clip range
camera.fog_end = 0.2 * camera.clip_far; // total foggy at 90% of clip range
ent_create ("fogband.mdl", vector(camera.x,camera.y,camera.z), follow);
}


action poly_on() //just to stop the default animations from running on static model for comparisons
{
my.ambient = 50;
set(my, POLYGON);
}

function bomb_event()

{

// do something bad to the player here wink..and add effects etc....

wait (1);

ent_remove(my);

}



function move_bomb()

{
my.pan = camera.pan;
my.tilt = camera.tilt;
my.emask |= (ENABLE_BLOCK | ENABLE_IMPACT | ENABLE_ENTITY);
my.roll +=15 *time_step;
my.event = bomb_event;

while (my)

{
c_move(my, vector(15 * time_step, 0, -1 * time_step), nullvector, IGNORE_SPRITES);
wait (1);
}

}

function follow()
{

while (fps_player <1) {wait (1);}
proc_mode = PROC_LATE;
fpsp = fps_player;
set(my, PASSABLE);
set(my,TRANSLUCENT);
set(my, LIGHT);
my.red=255;
my.green=255;
my.blue=255;
my.ambient = 100;
vec_fill(my.scale_x,10);
my.alpha = 50; // play with this value
while (fps_player !=NULL)
{
my.x = camera.x;
my.y = camera.y;
my.z = camera.z +20; // 40 = experimental value


wait(1);
}
}



Use the 'manual' Luke, the manual is your friend. 'Self reminder' smile

My WebPage
Re: Chase Camera [Re: KiwiBoy] #270274
06/07/09 11:43
06/07/09 11:43
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline
Expert
Germanunkol  Offline
Expert

Joined: Jun 2006
Posts: 2,640
Earth
Try this:

var cam_dist = 200;
var cam_height = 30;
var cam_speed = 2;
var camGoal[3];

function cam_follow()
{
while(1)
{
vec_set(camGoal[0],vector(-cam_dist,0,cam_height));
vec_rotate(camGoal[0],player.pan);
vec_add(camGoal[0],player.x);
//smooth out movement:
vec_diff(temp,camGoal[0],camera.x);
vec_scale(temp,cam_speed*time_step);
vec_add(camera.x,temp);

vec_set(camera.pan,player.pan);
wait(1);
}
}

KiwiBoy, I think your code may not work with a game where you can tilt more than 90 degrees... not sure if that's what you want though, micmac.


~"I never let school interfere with my education"~
-Mark Twain
Re: Chase Camera [Re: Germanunkol] #270276
06/07/09 11:48
06/07/09 11:48
Joined: Apr 2009
Posts: 298
Southern Oceans
KiwiBoy Offline
Member
KiwiBoy  Offline
Member

Joined: Apr 2009
Posts: 298
Southern Oceans
Yes your right smile
Thanks...


Use the 'manual' Luke, the manual is your friend. 'Self reminder' smile

My WebPage
Re: Chase Camera [Re: KiwiBoy] #270367
06/07/09 22:56
06/07/09 22:56
Joined: Jun 2009
Posts: 4
M
Micmac_Creations Offline OP
Guest
Micmac_Creations  Offline OP
Guest
M

Joined: Jun 2009
Posts: 4
Thanks for that, germanunkol. Ill try it today (public holiday:))


Micmac Creations
Re: Chase Camera [Re: Micmac_Creations] #270386
06/08/09 05:01
06/08/09 05:01
Joined: Jun 2009
Posts: 4
M
Micmac_Creations Offline OP
Guest
Micmac_Creations  Offline OP
Guest
M

Joined: Jun 2009
Posts: 4
I tried the script in my game, and the camera is giving a side on view. cry
I remember when i was programming the movement controls, i had to swop player.tilt and player.roll around and also add 90 degrees to player.pan. I don't know what I did wrong.


Micmac Creations
Re: Chase Camera [Re: Micmac_Creations] #270395
06/08/09 06:44
06/08/09 06:44
Joined: Jun 2009
Posts: 4
M
Micmac_Creations Offline OP
Guest
Micmac_Creations  Offline OP
Guest
M

Joined: Jun 2009
Posts: 4
Lol
Never mind
I was accidentally moving the player on the y axes.


Micmac Creations
Re: Chase Camera [Re: Micmac_Creations] #270450
06/08/09 11:39
06/08/09 11:39
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline
Expert
Germanunkol  Offline
Expert

Joined: Jun 2006
Posts: 2,640
Earth
all right, glad it helped.


~"I never let school interfere with my education"~
-Mark Twain
Re: Chase Camera [Re: Germanunkol] #313369
03/01/10 00:48
03/01/10 00:48
Joined: Dec 2008
Posts: 1
CA, USA
BRG Offline
Guest
BRG  Offline
Guest

Joined: Dec 2008
Posts: 1
CA, USA
I tried this and it worked great but how would i tilt the cam?

I think i should use "vec_to_angle" but I'm not sure how and where to use it.


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