I am experimenting using the code provided in tutorials.
I want to detect collision. I have used EVENT_IMPACT to detect the impact. However, I can see my two entities ( 2 planes - mig.mdl - from tutorial nr.10) are "merging" ( get one in the other) a lot until it is detected the impact. How to increase the resolution of detection? - if is possible? Bellow you can see the code.
I want the impact to be detected when the two entities are in contact.
Maybe is something wrong in my code? ( in this example I also can navigate with the joyistic and move the two entities)
///////////////////////////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////////////////////////////////////////////////////////
ENTITY* ent1 = NULL;
ENTITY* ent2 = NULL;
function click_event2()
{
if(event_type == EVENT_IMPACT){
error("Impact model 2!!!");
}
}
function click_event1()
{
if(event_type == EVENT_IMPACT){
error("Impact model 1!!!");
}
}
action cub2()
{
my.emask = (ENABLE_IMPACT);
my.event = click_event2;
while (1)
{
if (key_q) c_move (my, vector(2*time_step , 0, 0), nullvector, GLIDE);
if (key_w) c_move (my, vector(-2*time_step , 0, 0), nullvector, GLIDE);
if (key_e) c_move (my, vector(0 , 2*time_step, 0), nullvector, GLIDE);
if (key_r) c_move (my, vector(0 , -2*time_step, 0), nullvector, GLIDE);
wait (1);
}
///////////////////////////////
}
action cub1()
{
my.emask = (ENABLE_IMPACT);
my.event = click_event1;
while (1)
{
if (key_s) c_move (my, vector(2*time_step , 0, 0), nullvector, GLIDE);
if (key_a) c_move (my, vector(-2*time_step , 0, 0), nullvector, GLIDE);
if (key_z) c_move (my, vector(0 , 2*time_step, 0), nullvector, GLIDE);
if (key_x) c_move (my, vector(0 , -2*time_step, 0), nullvector, GLIDE);
wait (1);
}
///////////////////////////////
}
function main()
{
video_mode = 9;
mouse_mode = 2;
level_load ("work10.wmb");
vec_set(camera.x,vector(-240, 280, -40)); // place the camera at x = -500, y = 0, z = 100
ent1=ent_create("mig.mdl", vector(100, 300, -70), cub1);
set(ent1,POLYGON);
ent2=ent_create("mig2.mdl", vector(-240, 200, -70), cub2);
set(ent2,POLYGON);
wait (2);
while(1)
{
camera.y -= joy_force.x;
camera.x += joy_force.y;
if (joy_4)camera.pan+=0.3;
if (joy_5)camera.pan-=0.3;
if (joy_3) camera.z += 1;
if (joy_2) camera.z -= 1;
if (joy_8) camera.tilt += 0.1;
if (joy_9) camera.tilt -= 0.1;
if (joy_1 && joy_2)
{
camera.x = 0;
camera.y = 0;
camera.z = 0;
}
mouse_pos.x = mouse_cursor.x;
mouse_pos.y = mouse_cursor.y;
wait(1);
}
}
Last edited by CItrok; 01/28/10 12:23.