Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (Ayumi, 7th_zorro, 1 invisible), 1,060 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Line of sight detection and c_trace #238438
11/27/08 12:46
11/27/08 12:46
Joined: Nov 2008
Posts: 8
R
roBurky Offline OP
Newbie
roBurky  Offline OP
Newbie
R

Joined: Nov 2008
Posts: 8
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.

Re: Line of sight detection and c_trace [Re: roBurky] #238447
11/27/08 14:09
11/27/08 14:09
Joined: Aug 2005
Posts: 343
Germany
HPW Offline
Senior Member
HPW  Offline
Senior Member

Joined: Aug 2005
Posts: 343
Germany
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);
}


Last edited by HPW; 11/27/08 14:17.

Evil Blood (v. 0.52) RPG
Commport.de (Social Network Community)
Re: Line of sight detection and c_trace [Re: HPW] #238448
11/27/08 14:21
11/27/08 14:21
Joined: Nov 2008
Posts: 8
R
roBurky Offline OP
Newbie
roBurky  Offline OP
Newbie
R

Joined: Nov 2008
Posts: 8
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.

Re: Line of sight detection and c_trace [Re: roBurky] #238450
11/27/08 14:30
11/27/08 14:30
Joined: Aug 2005
Posts: 343
Germany
HPW Offline
Senior Member
HPW  Offline
Senior Member

Joined: Aug 2005
Posts: 343
Germany
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.


Evil Blood (v. 0.52) RPG
Commport.de (Social Network Community)
Re: Line of sight detection and c_trace [Re: HPW] #238473
11/27/08 16:19
11/27/08 16:19
Joined: Nov 2008
Posts: 8
R
roBurky Offline OP
Newbie
roBurky  Offline OP
Newbie
R

Joined: Nov 2008
Posts: 8
Thanks, that makes sense.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | 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