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
2 registered members (TipmyPip, 1 invisible), 18,699 guests, and 8 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
smoke effect on collision #168390
11/20/07 07:31
11/20/07 07:31
Joined: Apr 2007
Posts: 83
prog Offline OP
Junior Member
prog  Offline OP
Junior Member

Joined: Apr 2007
Posts: 83
hello,
am trying to make smoke effect for the AI car when ever it collides with other AI cars or the player car.

CODE:

//AI car action

action car
{
var waypoint_number = 0;
var target_coords; // the coordinates of the next waypoint on the path
var engine_handle;
var angle_diff;
var engine_offset; // creates a random (unique) engine sound for every car
my.race_over = 0;
my.counting_laps = 1;
my.laps = -1;
my.max_speed = 50; // initial value needed to start the car
my.min_speed = 50; // initial value needed to start the car
my.enable_scan = on; // the car is sensitive to scanning
my.event = make_way; // its event function will run if it is scanned

////////////////////////////////////////////////////////////////////////
my.enable_impact = on;
my.event = smoke_action;
////effect(smoke_action, 5, temp, vector(car1_speed,0,0));
////effect(smoke_action, 5, temp, vector(car2_speed,0,0));
////effect(smoke_action, 5, temp, vector(car3_speed,0,0));
///////////////////////////////////////////////////////////////////////////////

engine_offset = random(3); // generate a random value that will be used together with snd_tune to generate a unique engine sound
if (my.skill1 == 1) // don't forget to set skill1 = 1 for the first car, skill1 = 2 for the second car and so on
{
ent_path("car01"); // if skill1 = 1 the car will follow the path named "car01" without the quotes
car1 = me; // I'm car 1
}
if (my.skill1 == 2) // same thing for the rest of the cars
{
ent_path("car02");
car2 = me;
}
if (my.skill1 == 3)
{
ent_path("car03");
car3 = me;
}
while (race_started == 0) {wait (1);}
engine_handle = ent_playloop (my, engine_wav, 50); // play the engine sound in a loop
ent_waypoint(target_coords, 1); // set the target coordinates to the first point on the path
while (my.race_over == 0) // this loop will run until my.race_over = 1
{
temp.x = 60; // horizontal scanning angle
temp.y = 60; // vertical scanning angle
temp.z = 150; // scanning range
scan_entity (my.x, temp); // scan the cars in front of me on a distance of 150 quants

temp.x = target_coords.x - my.x; // get the vector that points towards the target
temp.y = target_coords.y - my.y;
temp.z = 0;
if (vec_to_angle (angle_diff.pan, temp) < 150) // closer than 150 quants to the target?
{
waypoint_number = ent_nextpoint(target_coords); // move towards the new point on the path
}
angle_diff.pan = ang(angle_diff.pan - my.pan); // get the difference angle
my.pan += my.car_speed * angle_diff.pan * 0.005; // change the pan angle of the car slowly
if (((waypoint_number > 65) || (waypoint_number < 8)) || ((waypoint_number > 34) && (waypoint_number < 49))) // horizontal areas of the track?
{
if (my.car_speed < (my.max_speed * time)) // and the speed is below max_speed?
{
my.car_speed += 1 * time; // increase the speed of the car
}
}
else // curved areas of the track
{
if (my.car_speed > (my.min_speed * time)) // and the speed is above min_speed?
{
my.car_speed -= 0.5 * time; // decrease the speed of the car
}
}
if (waypoint_number == 66) // close to the end of the lap?
{
pick_new_path(); // pick a new, random path from the ones that are available
}
if ((my.distance < 500) && (my.car_speed > 15))
{
my.car_speed -= my.distance / 200; // start slowly
}
my.skill28 = 0; // second skill used for car_speed, we are using skill27..skill29 (skill27 was defined as car_speed)
my.skill29 = 0; // third skill used for car_speed
move_mode = ignore_you + ignore_passable + glide;
my.skill2 = ent_move (my.car_speed, nullskill); // store the distance covered by this car in skill2
my.distance += my.skill2; // and store the total distance in my.distance (know which car is in front at a certain moment, etc)
snd_tune (engine_handle, 50, (my.skill2 * 5 + engine_offset), 0); // tune the sound depending on the "real" speed of the car (distance covered)

vec_set (temp, my.x);
temp.z -= 1000;
//trace_mode = ignore_me + ignore_passable + scan_texture;
//trace (my.x, temp); // trace 1000 quants below the car
c_trace (my.x, temp.x, ignore_me | ignore_passable | scan_texture);
if (str_cmpi ("checker1", tex_name)) // if we've got the texture named "checker1" (without the quotes)
{
add_laps(); // increase the number of laps
}
if (my.laps == max_laps) // end of race?
{
my.race_over = 1; // get out of the while loop after max_laps
place += 1;
if (place == 1) // i'm the first car that finishes the race?
{
if (my.skill1 == 1)
{
str_cpy (car1_str, "1st place: Green car Time: ");
str_for_num (temp_str, car1_time);
str_cat (car1_str, temp_str);
car1_txt.pos_y = 250;
car1_txt.visible = on;
}
if (my.skill1 == 2)
{
str_cpy (car2_str, "1st place: Red car Time: ");
str_for_num (temp_str, car2_time);
str_cat (car2_str, temp_str);
car2_txt.pos_y = 250;
car2_txt.visible = on;
}
if (my.skill1 == 3)
{
str_cpy (car3_str, "1st place: Blue car Time: ");
str_for_num (temp_str, car3_time);
str_cat (car3_str, temp_str);
car3_txt.pos_y = 250;
car3_txt.visible = on;
}
}
if (place == 2) // i'm the second car that finishes the race?
{
if (my.skill1 == 1)
{
str_cpy (car1_str, "2nd place: Green car Time: ");
str_for_num (temp_str, car1_time);
str_cat (car1_str, temp_str);
car1_txt.pos_y = 280;
car1_txt.visible = on;
}
if (my.skill1 == 2)
{
str_cpy (car2_str, "2nd place: Red car Time: ");
str_for_num (temp_str, car2_time);
str_cat (car2_str, temp_str);
car2_txt.pos_y = 280;
car2_txt.visible = on;
}
if (my.skill1 == 3)
{
str_cpy (car3_str, "2nd place: Blue car Time: ");
str_for_num (temp_str, car3_time);
str_cat (car3_str, temp_str);
car3_txt.pos_y = 280;
car3_txt.visible = on;
}
}
if (place == 3) // i'm the third car that finishes the race?
{
if (my.skill1 == 1)
{
str_cpy (car1_str, "3rd place: Green car Time: ");
str_for_num (temp_str, car1_time);
str_cat (car1_str, temp_str);
car1_txt.pos_y = 310;
car1_txt.visible = on;
}
if (my.skill1 == 2)
{
str_cpy (car2_str, "3rd place: Red car Time: ");
str_for_num (temp_str, car2_time);
str_cat (car2_str, temp_str);
car2_txt.pos_y = 310;
car2_txt.visible = on;
}
if (my.skill1 == 3)
{
str_cpy (car3_str, "3rd place: Blue car Time: ");
str_for_num (temp_str, car3_time);
str_cat (car3_str, temp_str);
car3_txt.pos_y = 310;
car3_txt.visible = on;
}
}
if (place == 4) // i'm the fourth car that finishes the race?
{
if (my.skill1 == 1)
{
str_cpy (car1_str, "4th place: Green car Time: ");
str_for_num (temp_str, car1_time);
str_cat (car1_str, temp_str);
car1_txt.pos_y = 340;
car1_txt.visible = on;
}
if (my.skill1 == 2)
{
str_cpy (car2_str, "4th place: Red car Time: ");
str_for_num (temp_str, car2_time);
str_cat (car2_str, temp_str);
car2_txt.pos_y = 340;
car2_txt.visible = on;
}
if (my.skill1 == 3)
{
str_cpy (car3_str, "4th place: Blue car Time: ");
str_for_num (temp_str, car3_time);
str_cat (car3_str, temp_str);
car3_txt.pos_y = 340;
car3_txt.visible = on;
}
}
finish_pan.visible = on;
}
wait(1);
}
while (my.car_speed > 1) // decrease the speed from its current speed to 1
{
my.car_speed -= 1 * time;
snd_tune (engine_handle, 50, my.car_speed * 5, 0); // and tune the sound accordingly
my.skill28 = 0;
my.skill29 = 0;
move_mode = ignore_you + ignore_passable + glide;
ent_move (my.car_speed, nullskill);
wait (1);
}
snd_stop (engine_handle); // stop the engine sound
if (place == 4) // race finished for all the cars?
{
while (finish_pan.alpha < 95)
{
finish_pan.alpha += 2 * time; // increase alpha
wait (1);
}
finish_pan.transparent = off; // the panel is opaque now
}
}

//PLAYER car action

// CarControl: Assigning this to car's chassis
action CarInit
{
// build a car and wait til all wheels are ready
ChassisInit();
while (wheelCounter<4) { wait(1); }
my.material = mat_metal;

mat_metal.power = 8;
mat_metal.diffuse_blue = 150;
mat_metal.diffuse_green = 150;
mat_metal.diffuse_red = 150;
mat_metal.specular_blue = 255;
mat_metal.specular_green = 200;
mat_metal.specular_red = 200;


UpdateSpeed(); // update rear wheel speed (continuous)
SpeedControl();// change speed (continuous)
SteerControl();// change heading (continuous)
player = my; // I'm the player
my.race_over = 0;
my.counting_laps = 1;
my.laps = -1;
my.albedo = 0
}

action FLInit
{
my.passable=on;
while(!pChassis) { wait(1);}
pFL=my;
InitWheel();
// make wheel constraint pointing up and towards center
wheelFL= phcon_add(PH_WHEEL, pChassis, my);
phcon_setparams1(wheelFL, my.x, vecUp, vecRight);
phcon_setparams2(wheelFL, vector(0,0,0), nullvector, vector(suspensionERP, suspensionCFM,0));
my.passable=off;
}
action FRInit
{
my.passable=on;
while (!pChassis) { wait(1);}
pFR=my;
InitWheel();
// make wheel constraint pointing up and towards center
wheelFR= phcon_add(PH_WHEEL, pChassis, my);
phcon_setparams1(wheelFR, my.x, vecUp, vecRight);
phcon_setparams2(wheelFR, vector(0,0,0), nullvector, vector(suspensionERP, suspensionCFM,0));
my.passable=off;
}
action RLInit
{
my.passable=on;
while (!pChassis) { wait(1);}
pRL=my;
InitWheel();
// make wheel constraint pointing up and towards center
wheelRL= phcon_add(PH_WHEEL, pChassis, my);
phcon_setparams1(wheelRL, my.x, vecUp, vecRight);
phcon_setparams2(wheelRL, vector(0,0,0), nullvector, vector(suspensionERP, suspensionCFM,0));
my.passable=off;
}
action RRInit
{
my.passable=on;
while (!pChassis) { wait(1);}
pRR=my;
InitWheel();
// make wheel constraint pointing up
wheelRR= phcon_add(PH_WHEEL, pChassis, my);
phcon_setparams1(wheelRR, my.x, vecUp, vecRight);
phcon_setparams2(wheelRR, vector(0,0,0), nullvector, vector(suspensionERP, suspensionCFM,0));
my.passable=off;
}

Re: smoke effect on collision [Re: prog] #168391
11/21/07 10:34
11/21/07 10:34
Joined: Jan 2007
Posts: 1,619
Germany
Scorpion Offline
Serious User
Happy Birthday Scorpion  Offline
Serious User

Joined: Jan 2007
Posts: 1,619
Germany
That is always the best, post a 2 miles code without the code tags and hope that someone will find something. I think it wouldn't be wrong to highlight the important parts for that collisions thing.Then someone could _maybe_ try to help you.

Thanks

Re: smoke effect on collision [Re: Scorpion] #168392
11/21/07 11:05
11/21/07 11:05
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Ánd put them between code tags.


Click and join the 3dgs irc community!
Room: #3dgs
Re: smoke effect on collision [Re: Joozey] #168393
11/21/07 12:34
11/21/07 12:34
Joined: Jan 2007
Posts: 1,619
Germany
Scorpion Offline
Serious User
Happy Birthday Scorpion  Offline
Serious User

Joined: Jan 2007
Posts: 1,619
Germany
i mentioned that already^^
but we can't say it too often, so: put it between the code tags

Re: smoke effect on collision [Re: Scorpion] #168394
11/21/07 16:59
11/21/07 16:59
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
yeah I mentioned that already too.... but we cant say that enough, so make sure to put the code in code tags! :\
Sorry, I was reading over it


Click and join the 3dgs irc community!
Room: #3dgs
Re: smoke effect on collision [Re: prog] #168395
11/22/07 09:12
11/22/07 09:12
Joined: Apr 2007
Posts: 83
prog Offline OP
Junior Member
prog  Offline OP
Junior Member

Joined: Apr 2007
Posts: 83
Quote:

hello,
am trying to make smoke effect for the AI car when ever it collides with other AI cars or the player car.

CODE:

//////////SMOKE Function //////////////

function smokeAction()
{
vec_randomize(temp,1.5);
//** extract passed values
var car_speed; car_speed= my.vel_x;
my.vel_x=0;
vec_add (my.vel_x, temp);
my.bmap = bmpSmoke;//bmap for smoke
my.move = on;
my.function = part_alphafade; // change to a shorter, faster function

if (random(2)>1)
{
// *****every other particle is white
my.bright = on;
my.alpha = 10 + random(10);
my.size= 1+car_speed*random(10);
} else {
my.alpha = 5 + random(25);
my.size= 5+car_speed*random(30);
}
}

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


//AI car action

action car
{
Code:

:
:


my.enable_scan = on; // the car is sensitive to scanning
my.event = make_way; // its event function will run if it is scanned


/////////////////ON_IMPACT = Smoke Effect //////////////////////////////////
//The cars on collision with player car or with the other AI cars produce smoke effect
my.enable_impact = on;
my.event = smokeAction;
effect(smokeAction, 5, temp, vector(car1_speed,0,0));//on_impact the car shud have this effect
effect(smokeAction, 5, temp, vector(car2_speed,0,0));
effect(smokeAction, 5, temp, vector(car3_speed,0,0));
///////////////////////////////////////////////////////////////////////////////


// //******generate a random value that will be used together with snd_tune to generate a unique engine sound

engine_offset = random(3);
if (my.skill1 == 1) // setting skill1 = 1 for the first car, skill1 = 2 for the second car and so on
{
ent_path("car01"); // if skill1 = 1 the car will follow the path named "car01"
car1 = me; // I'm car 1
}
:
:

//******* this loop will run until my.race_over = 1
while (my.race_over == 0)
{
temp.x = 60; // horizontal scanning angle
temp.y = 60; // vertical scanning angle
temp.z = 150; // scanning range

//****** scaning the cars in front of me on a distance of 150 quants
scan_entity (my.x, temp);

temp.x = target_coords.x - my.x; // get the vector that points towards the target
temp.y = target_coords.y - my.y;
temp.z = 0;
:
:
move_mode = ignore_you + ignore_passable + glide;
my.skill2 = ent_move (my.car_speed, nullskill); // store the distance covered by this car in skill2

//**** stores the total distance in my.distance (know which car is in front at a certain moment, etc)
my.distance += my.skill2;

vec_set (temp, my.x);
temp.z -= 1000;
c_trace (my.x, temp.x, ignore_me | ignore_passable | scan_texture);

:Code:

:
:




Last edited by prog; 11/23/07 07:13.
Re: smoke effect on collision [Re: prog] #168396
11/22/07 14:35
11/22/07 14:35
Joined: Jan 2007
Posts: 1,619
Germany
Scorpion Offline
Serious User
Happy Birthday Scorpion  Offline
Serious User

Joined: Jan 2007
Posts: 1,619
Germany
you have one try left...now don't use the quote tags...use the Code tags^^

Re: smoke effect on collision [Re: Scorpion] #168397
11/22/07 15:58
11/22/07 15:58
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
And adding a little readability wont be a terrible thing either, indent for example


Click and join the 3dgs irc community!
Room: #3dgs

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