Questions from the forum

Top  Previous  Next

Q: I want a character to face another one when it enters its c_scan cone of vision.

A: There you go.

 

function rotate_now()

{

       vec_set(temp,your.x);

       vec_sub(temp,my.x);

       vec_to_angle(my.pan,temp);

}

 

action towards_player // attach this action to the entities that need to be rotated towards the player

{

       my.ENABLE_SCAN = on;

       my.event = rotate_now;

}

 

action players_code

{

       var anim_percentage;

       var movement_speed;

       var distance_to_ground;

       player = my;

       while (1)

       {

               c_scan(my.x, my.pan, vector(360, 0, 300), SCAN_ENTS | SCAN_LIMIT | IGNORE_ME); // perform the scanning

               camera.x = player.x - 250 * cos(player.pan);

               camera.y = player.y - 250 * sin(player.pan);

               camera.z = player.z + 150;

               camera.pan = player.pan;

               camera.tilt = -20;

               my.pan += 6 * (key_a - key_d) * time_step;

               vec_set (temp, my.x);

               temp.z -= 5000;

               distance_to_ground = c_trace (my.x, temp.x, ignore_me | use_box);

               movement_speed.x = 5 * (key_w - key_s) * time_step;

               movement_speed.y = 0;

               movement_speed.z = - (distance_to_ground - 17); // 17 = experimental value

               movement_speed.z = max (-35 * time_step, movement_speed.z); // 35 = falling speed

               c_move (my, movement_speed.x, nullvector, glide);

               if ((key_w == off) && (key_s == off))

               {

                       ent_animate(my, "stand", anim_percentage, anm_cycle);

               }

               else

               {

                       ent_animate(my, "walk", anim_percentage, anm_cycle);

               }

               anim_percentage += 5 * time_step;

               wait (1);

       }

}

 

 

Q: How can I create a panel-based background that repeats itself across the entire width of the screen?

A: The following engine update will allow the panels to tile across the screen; just set the desired size_x and / or size_y value if you want to do that.

 

PANEL test_pan =

{

       bmap = "art05.bmp";

       pos_x = 0;

       pos_y = 344;

       size_x = 800; // the game is running at a resolution of 800x600 pixels

       flags =  VISIBLE;

}

 

aum64_faq1

 

 

Q: I have tried to come up with a light source that changes its power gradually, but setting different lightrange values didn't work fine. Is there any other method I can try?

A: You can change the RGB components of the light; here's an example that uses a slider to do just that.

 

var my_value;

 

PANEL light_pan =

{

       bmap = "light.pcx";

       pos_x = 0;    

       pos_y = 0;   

       vslider (16, 71, 90, "slider.pcx", 0, 255, my_value);

       digits (15, 50, 3, _a4font, 1, my_value);

       flags = OVERLAY | VISIBLE;

}

 

action dynamic_light // place an entity in the level and attach it this action

{

       my.lightrange = 400; // use your own value here

       while (1)

       {

               my.red = my_value;

               my.green = my_value;

               my.blue = my_value;

               wait (1);

       }

}

 

 

Q: I would like to have a model animate using "walk" for 10 seconds, then "jump" for 10 seconds, "walk" again for 10 seconds, and so on. How do I do that?

A: Use this example.

 

action two_animations()

{

       var anim_speed;

       while (1)

       {

               my.skill88 = 0;

               while (my.skill88 < 10) // play this animation for 10 seconds

               {

                       my.skill88 += time_step / 16;

                       anim_speed += 2 * time_step; // 2 = walk animation speed

                       ent_animate(my, "walk", anim_speed, ANM_CYCLE);

                       wait (1);

               }

               my.skill88 = 0;

               while (my.skill88 < 10) // play this animation for 10 seconds

               {

                       my.skill88 += time_step / 16;

                       anim_speed += 3 * time_step; // 3 = jump animation speed

                       ent_animate(my, "jump", anim_speed, ANM_CYCLE);

                       wait (1);

               }

               wait (1);

       }

}

 

 

Q: I'd like to be able to play a random soundtrack in my game.

A: Use the following sample as a base for your code.

 

var track_number;

var track_handle;

 

function random_tracks_startup()

{

       while (1)

       {

               track_number = 1 + total_frames % 5; // use 5 sound tracks in this example

               if (track_number == 1)

               {

                       track_handle = media_play("track1.wav", NULL, 50);

               }

               if (track_number == 2)

               {

                       track_handle = media_play("track2.wav", NULL, 50);

               }

               if (track_number == 3)

               {

                       track_handle = media_play("track3.wav", NULL, 50);

               }

               if (track_number == 4)

               {

                       track_handle = media_play("track4.wav", NULL, 50);

               }

               if (track_number == 5)

               {

                       track_handle = media_play("track5.wav", NULL, 50);

               }

               while (media_playing (track_handle)) {wait (1);} // wait until the current track has ended

       }

}

 

 

Q: I have a turret gun attached to a car. The turret needs to move with the car but also target other objects when I move the mouse. How can I do that?

A: Use this example.

 

var weapon_offset;

 

STRING weapon_mdl = "weapon.mdl";

 

function attach_weapon()

{

       proc_late(); // prevent shaking

       my.passable = on;

       while(you)

       {

               if (mouse_force.x) // if we move the mouse on x

               {

                       weapon_offset -= 2 * mouse_force.x * time_step;

               }

               if (mouse_force.y) // if we move the mouse on y

               {

                       weapon_offset += 2 * mouse_force.y * time_step;

               }

               vec_set(my.x, you.x);

               my.pan = you.pan + weapon_offset;

                 my.frame = you.frame;

                 my.next_frame = you.next_frame;

                 wait(1);

       }

       ent_remove(my);

}

 

action players_vehicle

{

       player = my;

       ent_create(weapon_mdl, NULLVECTOR, attach_weapon);

       while (1)

       {

               // put your car movement code here

               wait (1);

       }

}

 

 

Q: I have a box and I want to be able to push it off of a ledge in a realistic way. Is it possible to do that?

A: Here's an example that uses the template player code and a physics-based box; it doesn't get more "realistic" that this!

 

var kick_speed;

 

action physics_box

{

       ph_setgravity (vector(0, 0, -386));

       my.shadow = on;

       phent_settype (my, ph_rigid, ph_box);

       phent_setmass (my, 20, ph_box);

       phent_setfriction (my, 50);

       phent_setdamping (my, 50, 50);

       phent_setelasticity (my, 30, 30);

       while (!plBiped01_entity) {wait (1);} // make sure to use your own player pointer name everywhere in this action

       while (1)

       {

               kick_speed.x = 25; // kick speed

               kick_speed.y = 0;

               kick_speed.z = 5; // make it jump up a bit as well

               vec_rotate(kick_speed, plBiped01_entity.pan); // kick it depending on player's angle

               if (vec_dist (plBiped01_entity.x, my.x) < 70) // 70 is the distance that triggers the kicking

               {

                       phent_addvelcentral(my, kick_speed); // kick the box

               }

               wait (1);

       }

}

 

 

Q: Is it possible to draw several lines from the current position of the mouse pointer to a certain point for as long as the left mouse button is kept pressed?

A: Sure! Use the following snippet, press and hold the left mouse button and then move the mouse around.

 

function draw_lines(x1, y1, x2, y2)

{

       while(1)

       {

               draw_line(vector(x1, y1, 0), NULL, 100);

               draw_line(vector(x2, y2, 0), vector(250, 250, 250), 100);

               wait(1);

       }

}

 

function draw_startup()

{

       var mouse_temp;

       while(1)

       {

               mouse_temp.x = mouse_pos.x;

               mouse_temp.y = mouse_pos.y;

               while (mouse_left)

               {

                       draw_lines(mouse_temp.x, mouse_temp.y, mouse_pos.x, mouse_pos.y);

                       wait (1);

               }

               wait (1);

       }

}

 

aum64_faq2

 

 

Q: When I try to change the level using level_load this malfunction appear "Can't save/load in same frame". Can someone help me with this?

A: You are using level_load inside a loop or the instruction is triggered several times by an event function.

 

function old_loading()

{

       .................

       level_load ("newlevel.wmb");

       .................

}

 

Use something like this to get rid of the problem:

 

var just_once = 0;

 

function new_loading() // use this function

{

       .................

       if (just_once == 0)

       {

               just_once = 1;

               level_load ("newlevel.wmb");

       }

       .................

}

 

 

Q: I need to be able to sort out which one of my enemies is the closest to the player.

A: The following snippet uses c_scan to place a sprite above the head of the closest enemy.

 

function entity_marker()

{

       my.PASSABLE = on;

       wait (1);

       ent_remove (my);

}

 

function player_scanning()

{

       while (1)

       {

               c_scan(my.x, my.pan, vector(360, 0, 500), SCAN_ENTS | SCAN_LIMIT | IGNORE_ME);

               if (you)

               {

                       ent_create ("marker.pcx", vector (you.x, you.y, you.z + 60), entity_marker);

               }

               wait (1);

       }

}

 

function beeper()

{

       wait (1); // this would be your enemies' event function

}

 

action sensitive_enemies // attach this action to your enemies

{

       my.ENABLE_SCAN = on;

       my.event = beeper;

       // the rest of the code for your enemies goes here

}

 

action players_code // sample player code, just call player_scanning(); from within your player's action

{

       player_scanning(); // this is how you would call the function that does the scanning

       var anim_percentage;

       var movement_speed;

       var distance_to_ground;

       player = my;

       while (1)

       {

               camera.x = player.x - 250 * cos(player.pan);

               camera.y = player.y - 250 * sin(player.pan);

               camera.z = player.z + 150;

               camera.pan = player.pan;

               camera.tilt = -20;

               my.pan += 6 * (key_a - key_d) * time_step;

               vec_set (temp, my.x);

               temp.z -= 5000;

               distance_to_ground = c_trace (my.x, temp.x, ignore_me | use_box);

               movement_speed.x = 5 * (key_w - key_s) * time_step;

               movement_speed.y = 0;

               movement_speed.z = - (distance_to_ground - 17); // 17 = experimental value

               movement_speed.z = max (-35 * time_step, movement_speed.z); // 35 = falling speed

               c_move (my, movement_speed.x, nullvector, glide);

               if ((key_w == off) && (key_s == off))

               {

                       ent_animate(my, "stand", anim_percentage, anm_cycle);

               }

               else // the player is moving?

               {

                       ent_animate(my, "walk", anim_percentage, anm_cycle);

               }

               anim_percentage += 5 * time_step; // 5 = animation speed

               wait (1);

       }

}