C_trace or ent_next for entity Sight

Posted By: jumpman

C_trace or ent_next for entity Sight - 06/09/17 19:46

Hi everyone

How do you handle entities seeing each other? Do you periodically c_scan, and then trace back in the entity event?

Or do you use Ent_next and go through every entity and trace to each one? (well each one that is eligible for being searched, like a my.searchable skill)

What are the advantages and disadvantages of each? Both need to iterate through the whole list somehow correct?

Scan's advantage is that you can specify the cone right?
Posted By: Ch40zzC0d3r

Re: C_trace or ent_next for entity Sight - 06/09/17 20:48

c_scan is probably using a balanced tree so I guess its a way faster (it isnt there for the lulz only)
Posted By: 3run

Re: C_trace or ent_next for entity Sight - 06/09/17 21:45

Well, maybe you could store those entities (you don't want to handle this for all entities on the level, right? not props etc, but probably only specific type of entities) in a list of entities, and cycle through it (I made this to handle all AI in one loop, but could be used for some other needs I guess)? Then you could make c_traces and other checks (if needed)? This is just an idea, and it might not be the best for your needs, cause I don't know what you want to archive (and I'm too noob anyway).

If we are talking about AI stuff, I usually use c_scan (f.e. when player shoots and walks, he makes c_scan check around in a circle, to attract enemies), that triggers AI and then I do c_trace (if needed). Aside from that, I use c_scan from AI itself, so it kinda looks around, and if player is within the scannig cone, then make a trace to make sure that we can see him (and he isn't behind the wall or something). Something like this, but I'm not sure about how fast is this going to be, probably depends on how many npcs are you going to have, plus maybe don't c_scan too offten, make somekind of counter or something.


Best regards!
Posted By: Reconnoiter

Re: C_trace or ent_next for entity Sight - 06/09/17 22:15

Don't use ent_next loop each frame, it is slow if you have lots of entities to cycle through. Easiest is to use c_scan for detection and than optionally trace to check if entity can really see other entity.
If you want to cycle through many / all objects, store those objects in a pointer array and loop through them in a for loop.
vec_dist can also be helpful and is fast.

Anyone actually know if it is faster to have separate whiles for entities or if you loop through them each frame in a for or while loop? I guess the latter right?
Posted By: jumpman

Re: C_trace or ent_next for entity Sight - 06/10/17 02:27

Whether I chose c_scan or ent_next, I was planning on letting entities take turns on who can use it. Since it's line of sight, there would need to be a c_trace as well. Do you all use a trace within the event_detect function, with a wait(1)?

If entities are taking turns scanning, why would a single while loop with all the scans be faster?
Posted By: Reconnoiter

Re: C_trace or ent_next for entity Sight - 06/10/17 09:26

I just use the 'you' pointer that c_trace returns (if the trace hits something).

Quote:
If entities are taking turns scanning, why would a single while loop with all the scans be faster?
, I mean have a single loop for all the entity actions (including your scan/trace code) which supposedly saves some fps but I don't really know how much. (I went slightly offtopic)
Posted By: jumpman

Re: C_trace or ent_next for entity Sight - 06/11/17 04:41

Can I reliably and safely use a c_trace within an event_detect event with a wait(1)? (Ptr_for_handle as well to retrieve the entity if needed)
© 2024 lite-C Forums