I altered the code from AUM so that when I click it shoots trace and then deforms the terrain at the target...but it dosent do so. It beeps, so i know it got to the end of the code...but nothing is happening.
Here is my code.
Code:
function create_crate();
function deform(vertex_number);
entity* terrain1;
var vertex_dist[1090];
var hit_coords;
action terrain
{
terrain1 = my; // used by vec_for_mesh and vec_to_mesh
my.ENABLE_SHOOT = ON; // triggers events if it is clicked
my.event = create_crate;
while(1)
{
if (mouse_left == 1)
{
vec_set(temp, mouse_pos);
temp.z -= 500; // trace downwards 500 quants below
c_trace (mouse_pos,temp,ACTIVATE_SHOOT);
vec_set (hit_coords, target); // store rocket's coords before they get lost
}
wait(1);
}
}
function create_crate()
{
wait (1);
my.skill1 = 1; // set the index to 1
my.skill2 = 50000; // set a huge distance at first; skill2 will get smaller and smaller for the vertices that are closer and closer to the explosion
while (my.skill1 < 1090) // go through all the vertices (1...1089) on the 33x33 grid (not using vertex_dist[0])
{
vec_for_mesh (temp, terrain1, my.skill1); // sets temp to vertex1, 2, 3...
vertex_dist [my.skill1] = vec_dist (hit_coords.x, target); // measures the distance between temp (vertex1, 2, 3...) and hit_coords
if (vertex_dist[my.skill1] < my.skill2) // this vertex is closer than the others?
{
my.skill2 = vertex_dist[my.skill1]; // then it might be the one, so store the distance
my.skill3 = my.skill1; // and its index as well
}
my.skill1 += 1; // move on to the following vertex
}
deform (my.skill3);
}
function deform(vertex_number)
{
vec_for_mesh(temp, terrain1, vertex_number);
vec_scale (temp, 0.7);
vec_to_mesh (temp, terrain1, vertex_number);
ent_fixnormals (my, my.frame); // recalculate the normal vectors, not really needed
beep();
}