c_trace and USE_BOX and collision-group problems...

Posted By: EvilSOB

c_trace and USE_BOX and collision-group problems... - 08/10/10 12:40

Hi all.
I cant post my 'real' code here, cause its buried in some evil code. So I'll post a re-creation as close as I can.

Code:
ENTITY* bullet_template = { type="bullet.mdl"; }

function can_be_hit(VECTOR* source, ENTITY* targit, ENTITY* shape)
{
	//backup old "me" info
	ENTITY* old_me = me;			//save old "me" so it can be restored later.
	var     old_my_group = my.group;	//save old "me" collision group too.
	me.group = 30;				//set old "me" to a collision group that
							//	is ignored by this function
	//
	//backup old "targit" info
	var     old_targ_group = targit.group;	//save "targit" collision group too.
	targit.group = 30;				//set "targit" to a collision group that
								//	is ignored by this function
	//
	//set "me" to collision-hull of choice
	me = shape;		//set "me" to collision-template for USE_BOX tracing
	me.group = 30;	//set "me" to ignore-able collision group
	//
	//do the trace.  (IGNORE_PUSH should make it ignore group=30, correct?)
	var results = c_trace(source, targit.x, IGNORE_PASSABLE|USE_BOX|IGNORE_PUSH);
	//
	//restore old "me" and "targit" to the way they were
	me = old_me;				//restore old me into "me"
	me.group = old_me_group;		//restore old "me" collision group
	targit.group = old_targ_group;	//restore old "targit" collision group
	//
	return(results);	//return distance to target
}


action player_act()
{
	ENTITY* victim=NULL;	//pointer to selected enemy target
	...
	if((mouse_left)&&(victim))
	{
		var victim_range = can_be_hit(my.x, victim, bullet_template);
		if(victim_range <= bullet_range)	{	shoot();  	}
	}
	...
}



So what Im trying to do is this...
I want to call a function from an action, that will 'temporarily' replace the ME
with another entity in order to do a USE_BOX trace with its collision-hull,
and then put it back again.
And I NEED to be using the collision-groups system during the trace too,
but i dont know if its working at all.

Can anyone see any flaws in the program flow ?
(be aware there may be some coding bugs in this un-compiled EXAMPLE code)

In my real code I keep getting odd collisions with what I believe to be geometry,
but its so intermittant its hard to pin down... due to the other evil code around it...

Thanks guys...


Posted By: slowglider

Re: c_trace and USE_BOX and collision-group problems... - 08/10/10 12:53

var results = c_trace(source, targit.x, IGNORE_PASSABLE|USE_BOX|IGNORE_PUSH);

anyway cant you use IGNORE_ME anyway
Posted By: Helghast

Re: c_trace and USE_BOX and collision-group problems... - 08/10/10 13:05

before setting me = shape, make sure to do me = NULL.
otherwise the pointer to me will be overwritten to be shape (from the function this calls).

same goes for before me = old_me.

hope that was clear, otherwise i'll have to make a drawing that explains what goes wrong... but i somehow feel you dont really need that.

regards,
Posted By: EvilSOB

Re: c_trace and USE_BOX and collision-group problems... - 08/10/10 13:28

Thanks guys, but no joy yet.

slowlider : Simple typo, real code doesnt have it.

Helghast : Not applicable. Fully tested. The line "me = old_me" always
gets executed, which repairs any damage caused by the "me = shape".


But keep at it guys.

Hint : It is mainly the c-tracing issues Ive got the problem with...
Posted By: tD_Datura_v

Re: c_trace and USE_BOX and collision-group problems... - 08/10/10 15:11

Quite possibly, IGNORE_ME is almost mandatory.
Also my manual (,which is out-dated,) doesn't seem to mention anything about IGNORE_PUSH working with c_trace and groups.

Posted By: Helghast

Re: c_trace and USE_BOX and collision-group problems... - 08/10/10 15:19

Originally Posted By: tD_Datura_v
Quite possibly, IGNORE_ME is almost mandatory.
Also my manual (,which is out-dated,) doesn't seem to mention anything about IGNORE_PUSH working with c_trace and groups.


That gave me the right idea...

you should try to do c_ignore(30); before the trace, then it will ignore that group wink

regards,
Posted By: Rei_Ayanami

Re: c_trace and USE_BOX and collision-group problems... - 08/10/10 15:20

c_ignore(30,0);

the last number always must be zero wink
Posted By: EvilSOB

Re: c_trace and USE_BOX and collision-group problems... - 08/10/10 18:01

tD_Datura_v : Even though my example doesnt show it, I have already
tried with IGNORE_ME, IGNORE_CONTENT, and both together. No change.

quote:from the manual - c_trace entry
IGNORE_PUSH Ignores entities with a lower push or same group value than the given entity.
For ignoring certain entity groups, call c_ignore before c_trace.

TO ME "or same group value" means it ignores whatever entities have the same group-value as the me...
ASSUMING that by "the given entity", it means the "me" entity.


I have also tried with the c_ignore, but I fell in the same hole as Helghast, and tried
c_ignore(30); ... without the trailing zero... I'll try it again.
Posted By: EvilSOB

Re: c_trace and USE_BOX and collision-group problems... - 08/10/10 18:11

nah. still no change...

I think I'll need to build a test project just to see whats going on...

Thanks all the same guys..
Posted By: Helghast

Re: c_trace and USE_BOX and collision-group problems... - 08/11/10 07:29

Originally Posted By: EvilSOB

quote:from the manual - c_trace entry
IGNORE_PUSH Ignores entities with a lower push or same group value than the given entity.
For ignoring certain entity groups, call c_ignore before c_trace.

TO ME "or same group value" means it ignores whatever entities have the same group-value as the me...
ASSUMING that by "the given entity", it means the "me" entity.


Maybe this is a bug then, or a manual mistake.
I am using push values alot, and can confirm those work, but I only use them in combination with c_move not trace.

good luck.
regards,
Posted By: EvilSOB

Re: c_trace and USE_BOX and collision-group problems... - 08/11/10 15:58

No bug, and no manual mistake.
Ive tested the concept in a stand-alone-project and the traces work fine.

That is, using IGNORE_PUSH allows the trace to ignore other entities
with matching 'group' numbers, as long as larger than zero...
So no need to use "c_ignore" when you only want to ignore one group.

AND there is no problem combining it with USE_BOX, it still work OK.
As does USE_BOX on its own. It works fine there.

I HAVE YET TO TEST WITH LEVEL-GEOMETRY.... but I think it is
unlikely to yeild any problems, cause in my 'problem' code it
was failing on entities as well as geometry....

[EDIT] No problems with geometry either.
Obviously my "funky" code is doing something "TOO funky"...

© 2024 lite-C Forums