Q:
In Aum 21 the tanks have no gravity and if they are up in the air
they will not go down the bottom.
I know that this code was written for A5 but I'm trying to get it to
work for A6; can you help?
A:
Use the project from Aum36's faq as a base; it includes gravity, as well as slope
alignment for a car. Click here to download
the modified project.
Q: I was
wondering if you could show me how to set up a rotating camera? Say you are
in a room and you press 's' to start the camera rotating in around 360 degrees
and then press 's' to stop it.
A: Use the code below:
var camera_mode = 0;
var rotation_speed = 1.5;
view rotating_camera{}
starter set_camera()
{
sleep (1); // wait a bit more
rotating_camera.pos_x = 0;
rotating_camera.pos_y = 0;
rotating_camera.size_x = screen_size.x;
rotating_camera.size_y = screen_size.y;
}
function switch_cameras()
{
if (player == null) {return;}
camera_mode += 1;
if (camera_mode %2 == 1) // rotating camera?
{
rotating_camera.x = player.x;
rotating_camera.y = player.y;
rotating_camera.z = player.z;
rotating_camera.pan = player.pan;
rotating_camera.tilt = player.tilt;
rotating_camera.roll = player.roll;
rotating_camera.visible = on;
camera.visible = off;
while (camera_mode % 2 == 1)
{
rotating_camera.pan += rotation_speed
* time;
wait (1);
}
}
else
{
rotating_camera.visible = off;
camera.visible = on;
}
}
on_s = switch_cameras;
Q:
I'd need a little jump-pad
type code. I've positioned entities throughout the level, and when the
character
runs on them I'd like him to be thrusted about 30 - 40 scaled feet into
the air. I'd also like to have a sound file associated with the trigger.
A:
Click here to download the code for my old "Maniac
Miner" project from Aum3 that now includes jump pads as well.

Q:
I want to determine exactly where the bullet hits the
entity. How can I get the closest vertex of the model?
A:
Use the code below:
action enemy // attach this action to your enemy model
{
my.enable_impact = on;
my.enable_shoot = on;
my.enable_entity = on;
my.event = compute_shot_pos;
}
function compute_shot_pos()
{
var temp_vertex = 0;
var hit_vertex = 0;
var index = 1;
var temp_dist = 0;
var min_dist = 10000; // set to a big value on purpose
vec_set(bullet_pos, you.pos); // store bullet's coords before they
get lost (before the bullet disappears)
my.event = null; // don't react to other bullets from now on
wait (1); // now we can wait for a frame
while (index < ent_vertices(my)) // get the number of vertices
{
vec_for_vertex (temp_vertex, my, index); // store
the coordinates of the current vertex in temp_vertex
temp_dist = vec_dist(bullet_pos.x, temp_vertex.x);
// compute the distance from the vertex to the impact coordinates
if (temp_dist < min_dist) // if we have got
a tiny value
{
min_dist = temp_dist; // then
this will be the closest vertex, at least for now
hit_vertex = index; // and
we store the index
}
index += 1; // check the next vertex
}
my.event = compute_shot_pos; // the loop has ended, start reacting
to other bullets from now on
// hit_vertex contains the closest vertex number now
}
Q:
I'd like to have a panel that can be closed by clicking a small "X"
in the upper right corner. Is this possible?
A: Sure. Use the code below:
bmap mypanel_pcx = <mypanel.pcx>;
function close_panel;
panel mypanel_pan
{
bmap = mypanel_pcx;
layer = 20;
pos_x = 250;
pos_y = 50;
flags = overlay, refresh, visible;
on_click = close_panel;
}
function close_panel()
{
if ((pointer.x > mypanel_pan.pos_x + bmap_width(mypanel_pcx)
- 10) && (pointer.y < mypanel_pan.pos_y
+ 10)) // the "X" has 10x10 pixels
{
mypanel_pan.visible = off;
}
}

Q:
How
can I create a cone of particles?
A:
Use the code below:
bmap effect_tga = <effect.tga>;
function particle_cone();
function fade_particles();
action cone
{
my.invisible = on;
my.passable = on;
while(1)
{
effect(particle_cone, 20 * time, my.x, nullvector);
wait(1);
}
}
function particle_cone()
{
temp.x = random(10) - 5;
temp.y = random(10) - 5;
temp.z = random(5) + 5;
vec_set(my.vel_x,temp);
my.bmap = effect_tga;
my.size = 2.5;
my.flare = on;
my.bright = on;
my.move = on;
my.streak = on; // if your engine version supports it
my.alpha = 80;
my.lifespan = 50;
my.function = fade_particles;
}
function fade_particles()
{
my.alpha -= 2 * time;
if(my.alpha < 0) // not really needed
{
my.lifespan = 0;
}
}
Q:
How
can I smoothly fade one view into another?
A: Use the code below:
view second_camera{}
action set_second_camera // place any entity in the level and set its proper
position and orientation
{
my.invisible = on;
my.passable = on;
wait (3);
second_camera.pos_x = 0;
second_camera.pos_y = 0;
second_camera.size_x = screen_size.x;
second_camera.size_y = screen_size.y;
second_camera.alpha = 0;
second_camera.transparent = on;
camera.alpha = 100;
camera.transparent = on;
second_camera.x = my.x;
second_camera.y = my.y;
second_camera.z = my.z;
second_camera.pan = my.pan;
second_camera.tilt = my.tilt;
second_camera.roll = my.roll;
}
function toggle_cameras()
{
second_camera.visible = on;
while (second_camera.alpha < 99)
{
second_camera.alpha += 2 * time;
camera.alpha -= 2 * time;
wait (1);
}
camera.visible = off;
second_camera.transparent = off;
}
on_t = toggle_cameras;
Q:
How can I replace all the "a" characters in a string with "b" characters?
A: Use the example below:
var number_of_characters;
var string_index;
string initial_str;
string replaced_str;
string backup_str;
text tester_txt
{
layer = 200;
string = replaced_str;
flags = visible;
}
function replace_characters()
{
str_cpy(initial_str, "Mary is an awesome painter");
number_of_characters = str_len(initial_str);
string_index = 0;
str_cpy(replaced_str, "");
while (string_index < number_of_characters)
{
str_cpy (backup_str, initial_str);
str_clip(backup_str, string_index);
str_trunc(backup_str, number_of_characters -
string_index - 1);
if (str_cmpi(backup_str, "a") == 1)
// found an "a"?
{
str_cat(replaced_str, "b");
// replace it with a "b"
}
else
{
str_cat(replaced_str, backup_str);
// keep the current letter
}
string_index += 1;
}
}
on_r = replace_characters;
Q:
I'd like to be able to create objects (trees) at runtime and place them in front
of the player.
How
can
I
do
that?
A: Use this example:
string tree_mdl = <tree.mdl>;
function create_tree()
{
wait (1);
vec_set (temp.x, my.x);
temp.z -= 10000;
trace_mode = ignore_me + ignore_sprites + ignore_models + use_box;
my.z -= trace (my.pos, temp) + 20;
}
function place_trees()
{
temp.x = 200; // place the trees 200 quants in front of the player
temp.y = 0;
temp.z = 0;
vec_rotate (temp, player.pan);
vec_add (temp, player.x);
ent_create(tree_mdl, temp.x, create_tree); // create the tree
}
on_p = place_trees;