Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
1 registered members (Grant), 999 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
getting in and out of a car #312446
02/24/10 20:24
02/24/10 20:24
Joined: Feb 2010
Posts: 886
Random Offline OP
User
Random  Offline OP
User

Joined: Feb 2010
Posts: 886
I tryed to use the aum 88 to make a playercar code.
But with a physical car;

code

______________________________________________________________

var constr_front_left;
var constr_front_right;

var constr_back_left;
var constr_back_right;

var max_angle;
var stear_contr;

var max_speed = 10000;
var ang_force;
var speed_contr = 1500;


function wheel_physics_init_front()
{
phent_settype (my, PH_RIGID, PH_SPHERE);
phent_setmass (my, 25, PH_SPHERE);
phent_setgroup (my, 2);

phent_setfriction (my, 100);
phent_setdamping (my, 20, 20);
phent_setelasticity (my, 0, 100);
}

function wheel_physics_init_back()
{
phent_settype (my, PH_RIGID, PH_SPHERE);
phent_setmass (my, 35, PH_SPHERE);
phent_setgroup (my, 2);

phent_setfriction (my, 100);
phent_setdamping (my, 20, 20);
phent_setelasticity (my, 0, 100);
}

function front_tyre_left()
{
wheel_physics_init_front();

constr_front_left = phcon_add (PH_WHEEL, car, 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_front();

constr_front_right = phcon_add (PH_WHEEL, car, my);
phcon_setparams1 (constr_front_right, my.x, vector (0,0,1), nullvector);
phcon_setparams2 (constr_front_right, nullvector, nullvector, nullvector);
}


function back_tyre_left()
{
wheel_physics_init_back();

constr_back_left = phcon_add (PH_WHEEL, car, 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_back();

constr_back_right = phcon_add (PH_WHEEL, car, my);
phcon_setparams1 (constr_back_right, my.x, nullvector, vector (0,1,0));
phcon_setparams2 (constr_back_right, nullvector, nullvector, nullvector);
}

action car_init()
{
car = my;
while (!player) {wait (1);}

while (key_space) {wait (1);}
my.emask |= (ENABLE_IMPACT | ENABLE_ENTITY | ENABLE_BLOCK);
set (my, POLYGON);
c_setminmax(me);

phent_settype (car, PH_RIGID, PH_BOX);
phent_setmass (car, 65, PH_BOX);
phent_setgroup (car, 2);

phent_setfriction (car, 20);
phent_setdamping (car, 5, 5);
phent_setelasticity (car, 10, 100);

ent_create ("car_tyre_left.mdl", vector (car.x -65, car.y - 45, car.z - 20), back_tyre_left);
ent_create ("car_tyre_right.mdl", vector (car.x -65, car.y + 45, car.z - 20), back_tyre_right);

ent_create ("car_tyre_left.mdl", vector (car.x +65, car.y - 45, car.z - 20), front_tyre_left);
ent_create ("car_tyre_right.mdl", vector (car.x +65, car.y + 45, car.z - 20), front_tyre_right);

while (players_health > 0)
{
while (player_in_car == 0)
{
wait(1);
}

stear_contr = (key_d - key_a);

max_angle += stear_contr * 10 * 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 (950000, 5000, 0));
phcon_setparams2 (constr_front_right, vector (max_angle, max_angle, 0), nullvector, vector (950000, 5000, 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 (9500, 50, 0));
phcon_setparams2 (constr_front_right, vector (max_angle, max_angle, 0), nullvector, vector (9500, 50, 0));
}

speed_contr = (key_w - key_s);

ang_force = speed_contr * 100 * time_step;

phcon_setmotor (constr_back_left, nullvector, vector(-ang_force, max_speed, 100), nullvector);
phcon_setmotor (constr_back_right, nullvector, vector(-ang_force, max_speed, 100), nullvector);

ANGLE cam_ang;
var temp;
var rotspd=20;
var minang=10; var maxang=70;
var mindist=400; var maxdist=1000;
var cam_dist=400;

cam_ang.tilt=20;
cam_ang.roll=0;
cam_ang.pan= car.pan-180;

camera.roll = car.roll;
camera.tilt = car.tilt;
camera.x=car.x+cos(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt));
camera.y=car.y+sin(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt));
camera.z=car.z+sin(cam_ang.tilt)*cam_dist;
vec_set(temp,car.x);
vec_sub(temp,camera.x);
vec_to_angle(camera.pan,temp);
wait(1);
}
if (key_space)
{
while (key_space) {wait (1);}
player_in_car = 0;
player = NULL;
vec_set (player_pos.x, vector(10, -40, 55));
vec_rotate (player_pos.x, car.pan);
vec_add (player_pos.x, car.x);
you = ent_create("agent.mdl", player_pos, my_player);
you.skill99 = 1;
}
}

---------------------------------

And here is the player code

---------------------------------

action my_player()
{
while (!car) {wait (1);}
if (my.skill99 == 1)
{
my.pan = car.pan;
}
while (key_space) {wait (1);}
player = me;

c_setminmax(my);
set(player, FLAG8 | SHADOW);
set(my,UNLIT);
my.gravity = 6;
my.zoffset = 2;
player.push = -1;
player.group = -1;
c_setminmax(me);

while (players_health > 0)
{
pl_move();
pl_camera();
wait(1);
}
if ((vec_dist (player.x, car.x) < 100) && (key_space))
{
while (key_space) {wait (1);}
set (player, PASSABLE);
player_in_car = 1;
}
while (player_in_car == 1)
{
wait (1);
}
}
_______________________________________________________________

The problem is that I can controle the player with no problem but when im neer the car and press the space butten, nothing happens.

Doese somebody know what I did wrong?
thanks furthermore.



Re: getting in and out of a car [Re: Random] #312447
02/24/10 20:26
02/24/10 20:26
Joined: Feb 2010
Posts: 886
Random Offline OP
User
Random  Offline OP
User

Joined: Feb 2010
Posts: 886
Oh I almost forgot.
It must be something wrong in code becuse the playercar projeckt form the aum (88) worked perfecktly.



Re: getting in and out of a car [Re: Random] #312632
02/25/10 18:39
02/25/10 18:39
Joined: Feb 2010
Posts: 886
Random Offline OP
User
Random  Offline OP
User

Joined: Feb 2010
Posts: 886
Hmm, did I ask wrong or bad?



Re: getting in and out of a car [Re: Random] #312664
02/25/10 20:09
02/25/10 20:09
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
while (players_health > 0)
{
pl_move();
pl_camera();
wait(1);
}

// shouldn't the following lines be in your while loop ?

if ((vec_dist (player.x, car.x) < 100) && (key_space))
{
while (key_space) {wait (1);}
set (player, PASSABLE);
player_in_car = 1;
}
while (player_in_car == 1)
{
wait (1);
}
}


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends

Moderated by  HeelX, Spirit 

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