|
Non-symmetrical reactions on collision with symmetrical code
#257252
03/21/09 23:16
03/21/09 23:16
|
Joined: Mar 2009
Posts: 23
Siegewolf
OP
Newbie
|
OP
Newbie
Joined: Mar 2009
Posts: 23
|
I have a test case with two balls, moving along X-axis in opposite directions until they collide. My intention is that both of them disappear in collision. However, most of the time only one ball disappears and other proceeds further along x axis. Here is the code:
#include <acknex.h>
#include <default.c>
ENTITY* ball1;
ENTITY* ball2;
function collision_impact()
{
ent_remove(my);
}
action ball_move()
{
my.emask |= ENABLE_IMPACT;
my.event = collision_impact;
while (!key_ctrl) wait (1); // wait until the player presses the [ctrl] key
while (my != NULL)
{
c_move(my, vector(50 * time_step, 0, 0), nullvector, GLIDE);
wait (1);
}
}
function main()
{
video_mode = 9;
level_load ("");
vec_set(camera.x,vector(0, -1000, 0));
vec_set(camera.pan,vector(90, 0, 0));
ball1 = ent_create ("ball.mdl", vector(-500, 0, 0), ball_move);
ball2 = ent_create ("ball.mdl", vector(500, 0, 0), ball_move);
ball2.pan = 180;
}
I don't know why this is not working, where did I make mistake?
|
|
|
Re: Non-symmetrical reactions on collision with symmetrical code
[Re: Siegewolf]
#257258
03/22/09 01:17
03/22/09 01:17
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
as the engine only calculates 1 thing at a time, but so fast it seems they're done all at once, actually only 1 ball is colliding with the other, but the second one isn't as the first has been removed. personally i don't use events and would just do action ball_move()
{
while (!key_ctrl) wait (1); // wait until the player presses the [ctrl] key
while (me){
c_move(my, vector(50 * time_step, 0, 0), nullvector, GLIDE);
if(you){
ent_remove(you);
ent_remove(me);
}
wait (1);
}
} hope this helps
|
|
|
Re: Non-symmetrical reactions on collision with symmetrical code
[Re: MrGuest]
#257267
03/22/09 03:32
03/22/09 03:32
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Just a simple untested idea, but try function collision_impact()
{
wait(1);
ent_remove(my);
}
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Non-symmetrical reactions on collision with symmetrical code
[Re: Siegewolf]
#257546
03/23/09 21:14
03/23/09 21:14
|
Joined: Mar 2009
Posts: 23
Siegewolf
OP
Newbie
|
OP
Newbie
Joined: Mar 2009
Posts: 23
|
Thanks for the help folks  EvilSOB, your suggestion works well on test case but after some testing I noticed that it does not work too well on my real problem (it still sometimes happens that not both objects react properly). MrGuest your post gave me an idea for a new code that looks like this and works quite well for both test case and my real case. Here is improved code of test case:
#include <acknex.h>
#include <default.c>
ENTITY* ball1;
ENTITY* ball2;
STRING* command_kill = "kill";
function collision_impact()
{
my.string1 = command_kill;
you.string1 = command_kill;
}
action ball_move()
{
my.emask |= ENABLE_IMPACT;
my.event = collision_impact;
while (!key_ctrl) wait (1); // wait until the player presses the [ctrl] key
while (my != NULL)
{
c_move(my, vector(50 * time_step, 0, 0), nullvector, GLIDE);
if (my.string1 == command_kill)
{
ent_remove(me);
}
wait (1);
}
}
function main()
{
video_mode = 9;
level_load ("");
vec_set(camera.x,vector(0, -1000, 0));
vec_set(camera.pan,vector(90, 0, 0));
ball1 = ent_create ("ball.mdl", vector(-500, 0, 0), ball_move);
ball2 = ent_create ("ball.mdl", vector(500, 0, 0), ball_move);
ball2.pan = 180;
}
|
|
|
|