Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (AndrewAMD, TipmyPip, OptimusPrime), 15,229 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Non-symmetrical reactions on collision with symmetrical code #257252
03/21/09 23:16
03/21/09 23:16
Joined: Mar 2009
Posts: 23
S
Siegewolf Offline OP
Newbie
Siegewolf  Offline OP
Newbie
S

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:

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
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

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
Code:
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 Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Just a simple untested idea, but try
Code:
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
S
Siegewolf Offline OP
Newbie
Siegewolf  Offline OP
Newbie
S

Joined: Mar 2009
Posts: 23
Thanks for the help folks smile

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:

Code:
#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;
}



Moderated by  HeelX, Spirit 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1