AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Detect when a entity passes through anything a map has (https://forums.alliedmods.net/showthread.php?t=333834)

AnimalMonster 08-08-2021 21:29

Detect when a entity passes through anything a map has
 
Hi there, is there any way to check if a entity is passing though a object or any obstacle, house, box, etc a map can have?

Bugsy 08-08-2021 21:48

Re: Detect when a entity passes through anything a map has
 
Hook touch?

Celena Luna 08-08-2021 22:00

Re: Detect when a entity passes through anything a map has
 
PHP Code:

register_touch("entity1 classname""entity2 classname""fw_Touch_Entity2")

public 
fw_Touch_Entity(ent1ent2

it has to be an entity though, if it is some kind of map block then it can't be specific since it will always return id = 0

AnimalMonster 08-08-2021 22:13

Re: Detect when a entity passes through anything a map has
 
Everything that a map has is a entity(since i don't really know if yes or no), cuz if it is this makes everything a lot easier and if not then how can i check if an entity or player can pass through a point.

P.S. my goal is pathfinding algorithm for bots

Bugsy 08-08-2021 22:24

Re: Detect when a entity passes through anything a map has
 
Figure out the classname of all potential entities and use register_touch

Or use Ham_Touch to hook all entities touched by a player

PHP Code:

RegisterHamHam_Touch "player" "PlayerTouch" );

public 
PlayerTouchiToucher iTouched )
{
    
server_print"%d touched %d" iToucher iTouched );



Natsheh 08-09-2021 08:52

Re: Detect when a entity passes through anything a map has
 
Its every important to check entities validity in the touch function because its called many times depending on player frame per second

DJEarthQuake 08-09-2021 09:22

Re: Detect when a entity passes through anything a map has
 
Quote:

Originally Posted by AnimalMonster (Post 2754813)
Hi there, is there any way to check if a entity is passing though a object or any obstacle, house, box, etc a map can have?

PHP Code:

stock Float:is_user_outside(id)
{
    new 
Float:vOrigin[3], Float:fDist;
    
pev(idpev_originvOrigin);
    
fDist vOrigin[2];
    while(
engfunc(EngFunc_PointContentsvOrigin) == CONTENTS_EMPTY)
        
vOrigin[2] += 5.0;
    if(
engfunc(EngFunc_PointContentsvOrigin) == CONTENTS_SKY)
        return (
vOrigin[2] - fDist);
    return 
0.0;


This is not intended to be a 1 all end all just another tool to help achieve the results. Contents can be changed to water, lava, etc.

Edit:
I just read your pathfinding goal comment. Good luck with that!

HamletEagle 08-09-2021 10:44

Re: Detect when a entity passes through anything a map has
 
Quote:

Originally Posted by AnimalMonster (Post 2754820)
Everything that a map has is a entity(since i don't really know if yes or no), cuz if it is this makes everything a lot easier and if not then how can i check if an entity or player can pass through a point.

P.S. my goal is pathfinding algorithm for bots

What do you mean by"everything that a map has"? If you mean the actual map(walls, boxes, doors) then they are all part of "worldspawn" entity(id = 0).
Anyway, you don't need to list all possible entities to check if it's passable or not. You typically use a traceline to "scan" ahead. If the trace hits something then there is an obstacle in the way - it can also tell you useful information like the location of the obstacle. Also, I don't see how hooking touch is useful for pathfinding. You need to plan ahead and move only when you have a route, you don't move the bot in real-time while you search - that would look extremely silly.

Extra note 1: running a pathfinding algorithm in real-time will be extremely computationally expensive. At the very least you should pre-compute a node graph and run pathfinding over it. DO NOT explore the map and run pathfinding at the same time for every single bot that needs to move, it will completely overwhelm the server and it will be VERY far from real-time performance. Ideally, you want to use some kind of navmesh built on top of the node graph to reduce the number of edges that need to be explored and hopefully the number of runs of your pathfinding algorithm.
Extra note 2: you should consider implementing such algorithms in a module and you should be familiar with data structures like priority queues if you want to get a decent complexity out of your algorithm. I suggest you look into A*, or, if you plan to use this in smaller maps you may also use something called LRTA*(real time A*). Let the algorithm learn and pre-compute the matrix H and save it to disk. Later, when you want to execute movement you just need to follow the matrix(which will be an inexpensive operation). The only issue is if your map is big(covered using a lot of graph nodes) the matrix will get extremely big, that's why I suggest you use this only if your map is small or employ other techniques like dividing the map into multiple sections and generating a matrix for each section - each section will be smaller than the entire map thus resulting in a smaller matrix.

AnimalMonster 09-04-2021 20:29

Re: Detect when a entity passes through anything a map has
 
Quote:

Originally Posted by HamletEagle (Post 2754867)
What do you mean by"everything that a map has"? If you mean the actual map(walls, boxes, doors) then they are all part of "worldspawn" entity(id = 0).
Anyway, you don't need to list all possible entities to check if it's passable or not. You typically use a traceline to "scan" ahead. If the trace hits something then there is an obstacle in the way - it can also tell you useful information like the location of the obstacle. Also, I don't see how hooking touch is useful for pathfinding. You need to plan ahead and move only when you have a route, you don't move the bot in real-time while you search - that would look extremely silly.

Extra note 1: running a pathfinding algorithm in real-time will be extremely computationally expensive. At the very least you should pre-compute a node graph and run pathfinding over it. DO NOT explore the map and run pathfinding at the same time for every single bot that needs to move, it will completely overwhelm the server and it will be VERY far from real-time performance. Ideally, you want to use some kind of navmesh built on top of the node graph to reduce the number of edges that need to be explored and hopefully the number of runs of your pathfinding algorithm.
Extra note 2: you should consider implementing such algorithms in a module and you should be familiar with data structures like priority queues if you want to get a decent complexity out of your algorithm. I suggest you look into A*, or, if you plan to use this in smaller maps you may also use something called LRTA*(real time A*). Let the algorithm learn and pre-compute the matrix H and save it to disk. Later, when you want to execute movement you just need to follow the matrix(which will be an inexpensive operation). The only issue is if your map is big(covered using a lot of graph nodes) the matrix will get extremely big, that's why I suggest you use this only if your map is small or employ other techniques like dividing the map into multiple sections and generating a matrix for each section - each section will be smaller than the entire map thus resulting in a smaller matrix.

Thanks for the extra notes which are very helpful but as you suggested me to do that in a module... that would be kinda VERY HARD not to say that the path-finding algorithm would also be SUPER hard, maybe this is going to be a future project, and yeah i was talking about "worldspawn" entity.

but also, the FL_ONGROUND flag is only when you're on the ground of the map or even if you are on objects ? (didn't test it out since i have some other things i'm doing and also learning about)

CrazY. 09-05-2021 09:22

Re: Detect when a entity passes through anything a map has
 
For determining if an entity is on ground or not you'd better tracing a line down and cheking the fraction.

As for the pathfinding problem, Counter-Strike pathfinding seems to be using a grid to represent the map. Implementing the algorithm wouldn't be too hard, the actual problem would be to generate the graph.

Would have to look through ReGameDLL source to check how CS create the graphs. Alternatively you could do something similar to podbots, where you have to manually add the points, depending on what you're working on this may be sufficient.

Quote:

Originally Posted by CrazY. (Post 2755953)
Trace a line down from the player current origin and you'll get the "on ground" position.

Code:

new Float:start[3], Float:end[3]
pev(id, pev_origin, start)
end[0] = start[0]
end[1] = start[1]
end[2] = start[2] - 8192.0

// with IGNORE_MONSTERS, the trace will ignore players
// you may want to replace with DONT_IGNORE_MONSTERS
engfunc(EngFunc_TraceLine, start, end, IGNORE_MONSTERS, id, 0)

new Float:fraction
get_tr2(0, TR_flFraction, fraction)

if (fraction != 1.0)
        get_tr2(0, TR_vecEndPos, end)


// end[] is now the position on ground
// do something...

And to get the origin in front of the player:

Code:

new Float:start[3], Float:viewOfs[3]

pev(id, pev_origin, start)
pev(id, pev_view_ofs, viewOfs)
start[0] += viewOfs[0]
start[1] += viewOfs[1]
start[2] += viewOfs[2]

new Float:velocity[3], Float:end[3]

// replace 250 with the desired distance
velocity_by_aim(id, 250, velocity)

end[0] = start[0] + velocity[0]
end[1] = start[1] + velocity[1]
end[2] = start[2] + velocity[2]

engfunc(EngFunc_TraceLine, start, end, IGNORE_MONSTERS, id, 0)

new Float:fraction
get_tr2(0, TR_flFraction, fraction)

if (fraction != 1.0)
        get_tr2(0, TR_vecEndPos, end)

// end[] is now the position in front of the player
// do something...

In both cases the entity may end up getting stuck. If that happens, get TR_vecPlaneNormal, multiply by scalar X, where X is an arbitrary given value, you'll have to test to determine what's the proper value, start with 15.0, then add the result to end[].



All times are GMT -4. The time now is 02:39.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.