0 registered members (),
16,302
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Very big problem with camera!
#324388
05/20/10 15:50
05/20/10 15:50
|
Joined: May 2010
Posts: 22
XardasBeginer
OP
Newbie
|
OP
Newbie
Joined: May 2010
Posts: 22
|
Good morning. I have problem with camera. My code is: #include <default.c>; #include <acknex.h>;
//zmienne itd. var constr_front_left; var constr_front_right;
var constr_back_left; var constr_back_right;
VECTOR mom_speed; var max_angle; var stear_contr;
var max_speed = 1500; var ang_force; var speed_contr;
VECTOR* vec_gravity = {x = 0; y = 0; z = -1800;}
ENTITY* chassis;
function wheel_physics_init() { set (my, SHADOW); phent_settype (my, PH_RIGID, PH_SPHERE); phent_setmass (my, 30, PH_SPHERE); phent_setgroup (my, 2); phent_setfriction (my, 100); phent_setdamping (my, 20, 20); phent_setelasticity (my, 0, 100); }
///Koła przednie function front_tyre_left() { wheel_physics_init(); constr_front_left = phcon_add (PH_WHEEL, chassis, my); phcon_setparams1 (constr_front_left, my.x, vector (0,0,1), nullvector); phcon_setparams2 (constr_front_left, nullvector, nullvector, nullvector); }
function front_tyre_right() { wheel_physics_init(); constr_front_right = phcon_add (PH_WHEEL, chassis, my); phcon_setparams1 (constr_front_right, my.x, vector (0,0,1), nullvector); phcon_setparams2 (constr_front_right, nullvector, nullvector, nullvector); }
///Koła tylne function back_tyre_left() { wheel_physics_init(); constr_back_left = phcon_add (PH_WHEEL, chassis, my); phcon_setparams1 (constr_back_left, my.x, nullvector, vector (0,1,0)); phcon_setparams2 (constr_back_left, nullvector, nullvector, nullvector); }
function back_tyre_right() { wheel_physics_init(); constr_back_right = phcon_add (PH_WHEEL, chassis, my); phcon_setparams1 (constr_back_right, my.x, nullvector, vector (0,1,0)); phcon_setparams2 (constr_back_right, nullvector, nullvector, nullvector); }
function chassis_init() { chassis = my; set (chassis, SHADOW); //Zmienne fizyki phent_settype (chassis, PH_RIGID, PH_BOX); // rigid and box as collision hull phent_setmass (chassis, 15, PH_BOX); // lighter than wheels to avoid tilt phent_setgroup (chassis, 2); // all parts of the car in one group --> no collision phent_setfriction (chassis, 20); phent_setdamping (chassis, 5, 5); phent_setelasticity (chassis, 10, 100); // only little bouncing //zainicjuj koła auta //tylne ent_create ("car_tyre_left.mdl", vector (chassis.x - 65, chassis.y - 45, chassis.z - 20), back_tyre_left); ent_create ("car_tyre_right.mdl", vector (chassis.x - 65, chassis.y + 45, chassis.z - 20), back_tyre_right); //przednie ent_create ("car_tyre_left.mdl", vector (chassis.x + 65, chassis.y - 45, chassis.z - 20), front_tyre_left); ent_create ("car_tyre_right.mdl", vector (chassis.x + 65, chassis.y + 45, chassis.z - 20), front_tyre_right); wait(1); } void main() { level_load ("map.hmp"); wait(2); //Auto ent_create ("chassis.mdl", vector (0,0, 100), chassis_init); video_set (1024, 768, 0, 0); //ustaw 1024x768 window mode wait(2); vec_set(camera.x,vector(-150,0,50)); vec_set (camera.x,vector(-500,0,0)); vec_rotate (camera.x,camera.pan); vec_add (camera.x,chassis.x);
//Zainicjuj system fizyczny ph_setgravity (vec_gravity); ph_fps_max_lock = 1000;//500
///Szybkość i skręt while (1) { ///Skręcanie stear_contr = (key_d - key_a);//d = 1, a = -1, a & d = 0 max_angle += stear_contr * 3 * time_step; max_angle = clamp (max_angle, -30, 30); if (stear_contr != 0) { phcon_setparams2 (constr_front_left, vector (max_angle, max_angle, 0), nullvector, vector (95000, 500, 0)); phcon_setparams2 (constr_front_right, vector (max_angle, max_angle, 0), nullvector, vector (95000, 500, 0)); } else { max_angle = max_angle * (1 - (0.25 * time_step)); if (abs(max_angle) < 1) max_angle = 0; phcon_setparams2 (constr_front_left, vector (max_angle, max_angle, 0), nullvector, vector (95000, 500, 0)); phcon_setparams2 (constr_front_right, vector (max_angle, max_angle, 0), nullvector, vector (95000, 500, 0)); } ///Prędkość speed_contr = (key_w - key_s);//w = 1, s = -1, w & s = 0 ang_force = speed_contr * 1000 * time_step;
phcon_setmotor (constr_back_left, nullvector, vector(-ang_force, max_speed, 0), nullvector); phcon_setmotor (constr_back_left, nullvector, vector(-ang_force, max_speed, 0), nullvector); wait(1); } } And, my camera DON'T follow this object "chassis"!!! I'm compliling this in Lite-C, but i have got Gamestudio a7 30 days trial. Oh, and please, don't write in German language And, don't look for comments - it's in polish language 
Last edited by XardasBeginer; 05/20/10 15:51.
|
|
|
Re: Very big problem with camera!
[Re: XardasBeginer]
#324390
05/20/10 16:01
05/20/10 16:01
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
How is it supposed to follow the camera? You adjust the camera position one time. You need to put this in a loop if you want the camera to follow.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: Very big problem with camera!
[Re: XardasBeginer]
#324395
05/20/10 16:13
05/20/10 16:13
|
Joined: Sep 2009
Posts: 496
Progger
Senior Member
|
Senior Member
Joined: Sep 2009
Posts: 496
|
try this maybe it works :
#include <default.c>;
#include <acknex.h>;
//zmienne itd.
var constr_front_left;
var constr_front_right;
var constr_back_left;
var constr_back_right;
VECTOR mom_speed;
var max_angle;
var stear_contr;
var max_speed = 1500;
var ang_force;
var speed_contr;
VECTOR* vec_gravity = {x = 0; y = 0; z = -1800;}
ENTITY* chassis;
function wheel_physics_init()
{
set (my, SHADOW);
phent_settype (my, PH_RIGID, PH_SPHERE);
phent_setmass (my, 30, PH_SPHERE);
phent_setgroup (my, 2);
phent_setfriction (my, 100);
phent_setdamping (my, 20, 20);
phent_setelasticity (my, 0, 100);
}
///Koła przednie
function front_tyre_left()
{
wheel_physics_init();
constr_front_left = phcon_add (PH_WHEEL, chassis, my);
phcon_setparams1 (constr_front_left, my.x, vector (0,0,1), nullvector);
phcon_setparams2 (constr_front_left, nullvector, nullvector, nullvector);
}
function front_tyre_right()
{
wheel_physics_init();
constr_front_right = phcon_add (PH_WHEEL, chassis, my);
phcon_setparams1 (constr_front_right, my.x, vector (0,0,1), nullvector);
phcon_setparams2 (constr_front_right, nullvector, nullvector, nullvector);
}
///Koła tylne
function back_tyre_left()
{
wheel_physics_init();
constr_back_left = phcon_add (PH_WHEEL, chassis, my);
phcon_setparams1 (constr_back_left, my.x, nullvector, vector (0,1,0));
phcon_setparams2 (constr_back_left, nullvector, nullvector, nullvector);
}
function back_tyre_right()
{
wheel_physics_init();
constr_back_right = phcon_add (PH_WHEEL, chassis, my);
phcon_setparams1 (constr_back_right, my.x, nullvector, vector (0,1,0));
phcon_setparams2 (constr_back_right, nullvector, nullvector, nullvector);
}
function chassis_init()
{
chassis = my;
set (chassis, SHADOW);
//Zmienne fizyki
phent_settype (chassis, PH_RIGID, PH_BOX); // rigid and box as collision hull
phent_setmass (chassis, 15, PH_BOX); // lighter than wheels to avoid tilt
phent_setgroup (chassis, 2); // all parts of the car in one group --> no collision
phent_setfriction (chassis, 20);
phent_setdamping (chassis, 5, 5);
phent_setelasticity (chassis, 10, 100); // only little bouncing
//zainicjuj koła auta
//tylne
ent_create ("car_tyre_left.mdl", vector (chassis.x - 65, chassis.y - 45, chassis.z - 20), back_tyre_left);
ent_create ("car_tyre_right.mdl", vector (chassis.x - 65, chassis.y + 45, chassis.z - 20), back_tyre_right);
//przednie
ent_create ("car_tyre_left.mdl", vector (chassis.x + 65, chassis.y - 45, chassis.z - 20), front_tyre_left);
ent_create ("car_tyre_right.mdl", vector (chassis.x + 65, chassis.y + 45, chassis.z - 20), front_tyre_right);
wait(1);
}
void main()
{
level_load ("map.hmp");
wait(2);
//Auto
ent_create ("chassis.mdl", vector (0,0, 100), chassis_init);
video_set (1024, 768, 0, 0); //ustaw 1024x768 window mode
wait(2);
//Zainicjuj system fizyczny
ph_setgravity (vec_gravity);
ph_fps_max_lock = 1000;//500
///Szybkość i skręt
while (1)
{
vec_set(camera.x,vector(-150,0,50));
vec_set (camera.x,vector(-500,0,0));
vec_rotate (camera.x,camera.pan);
vec_add (camera.x,chassis.x);
///Skręcanie
stear_contr = (key_d - key_a);//d = 1, a = -1, a & d = 0
max_angle += stear_contr * 3 * time_step;
max_angle = clamp (max_angle, -30, 30);
if (stear_contr != 0)
{
phcon_setparams2 (constr_front_left, vector (max_angle, max_angle, 0), nullvector, vector (95000, 500, 0));
phcon_setparams2 (constr_front_right, vector (max_angle, max_angle, 0), nullvector, vector (95000, 500, 0));
}
else
{
max_angle = max_angle * (1 - (0.25 * time_step));
if (abs(max_angle) < 1)
max_angle = 0;
phcon_setparams2 (constr_front_left, vector (max_angle, max_angle, 0), nullvector, vector (95000, 500, 0));
phcon_setparams2 (constr_front_right, vector (max_angle, max_angle, 0), nullvector, vector (95000, 500, 0));
}
///Prędkość
speed_contr = (key_w - key_s);//w = 1, s = -1, w & s = 0
ang_force = speed_contr * 1000 * time_step;
phcon_setmotor (constr_back_left, nullvector, vector(-ang_force, max_speed, 0), nullvector);
phcon_setmotor (constr_back_left, nullvector, vector(-ang_force, max_speed, 0), nullvector);
wait(1);
}
}
WFG Progger 
|
|
|
Re: Very big problem with camera!
[Re: XardasBeginer]
#324401
05/20/10 16:50
05/20/10 16:50
|
Joined: Sep 2009
Posts: 496
Progger
Senior Member
|
Senior Member
Joined: Sep 2009
Posts: 496
|
You can not fix that Just a little joke change the old camera code with this code and put it in the while loop camera.x = chassis.x - 200 * sin(chassis.pan); camera.y = chassis.y - 200 * cos(chassis.pan); camera.z=chassis.z+10 camera.pan = chassis.pan ; // face the player WFG PRogger
Last edited by Progger; 05/20/10 16:51.
|
|
|
Re: Very big problem with camera!
[Re: XardasBeginer]
#324404
05/20/10 17:06
05/20/10 17:06
|
Joined: Sep 2009
Posts: 496
Progger
Senior Member
|
Senior Member
Joined: Sep 2009
Posts: 496
|
yes im stupid i forgot this ; at the end  here so its correct camera.z= chassis.z+10; WFG Progger 
|
|
|
Re: Very big problem with camera!
[Re: XardasBeginer]
#324405
05/20/10 17:07
05/20/10 17:07
|
Joined: Aug 2009
Posts: 1,438 Spain
painkiller
Serious User
|
Serious User
Joined: Aug 2009
Posts: 1,438
Spain
|
camera.x = chassis.x - 200 * sin(chassis.pan); camera.y = chassis.y - 200 * cos(chassis.pan); camera.z=chassis.z+10; camera.pan = chassis.pan; // face the player
3D Gamestudio A8 Pro AMD FX 8350 4.00 Ghz 16GB RAM Gigabyte GeForce GTX 960 4GB
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|