Line of sight detection and c_trace

Posted By: roBurky

Line of sight detection and c_trace - 11/27/08 12:46

Hello,

I'm trying to implement some line-of-sight detection for an entity in a game I'm trying to make.

From poking around in some of the shooter templates, it looked like c_trace might be a way to do this. However, my attempts to use it so far have not worked. This is the code I'm using at the moment:

Code:
	while (1)
	{
		c_trace(me,ball,IGNORE_ME + IGNORE_PASSABLE + IGNORE_PASSENTS);
		if (you != NULL)
		{
			alert = 1;
		}
		wait(1);
	}


'me' is the entity doing the detection. 'ball' is the player object it is trying to detect. If I understand what I'm reading in the help files correctly, if c_trace finds an entity between the two positions, it should set 'you' to the name of the entity, and therefore the if statement should become true.

However, 'you' never seems to become anything other than null.

Am I misunderstanding how this function works? Is there some other reason this might not be working? Can anyone provide me with another simple method of implementing what I'm trying to do?

Any help greatly appreciated.
Posted By: HPW

Re: Line of sight detection and c_trace - 11/27/08 14:09

No, this is the right way to do it.
Make sure your entity between the two entities me and ball is not passable. (Code: reset(me, PASSABLE);)
I don't know if it's important but you should use | instead of + as seperator for the flags of c_trace in Lite-C (filename.c). + was the seperator of C-Script (filename.wdl) in the past.
If your ball entity is not passable then it is also be set to the you pointer after c_trace!

Your code should look like this for Lite-C:
Code:
while(1)
{
  c_trace(my.x, ball.x, IGNORE_ME | IGNORE_PASSABLE | IGNORE_PASSENTS);
  if ((you != NULL) && (you != ball))
  {
     alert = 1;
  }
  wait(1);
}

Posted By: roBurky

Re: Line of sight detection and c_trace - 11/27/08 14:21

It is the ball I'm hoping to detect. I think I set the if statement to go true for anything other than 'you == null' in testing while trying to figure out how the c_trace worked.

I added the my.x and ball.x in your code to mine, and it appears to be working, thank you! Although I'm a little confused - I thought my.x would only be the x coordinate.
Posted By: HPW

Re: Line of sight detection and c_trace - 11/27/08 14:30

If you use a vector for a function like c_trace(VECTOR startpos, VECTOR endpos, var mode); and you just give it one position like my.x then it gets the next two positions automatically. But if you don't give it a position of your entity then I think it gets a pointer or the first three parameters of your entity and this aren't x, y and z.
Posted By: roBurky

Re: Line of sight detection and c_trace - 11/27/08 16:19

Thanks, that makes sense.
© 2024 lite-C Forums