Raised This Month: $51 Target: $400
 12% 

Detect when a entity passes through anything a map has


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
AnimalMonster
Senior Member
Join Date: May 2020
Old 08-08-2021 , 21:29   Detect when a entity passes through anything a map has
Reply With Quote #1

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?

Last edited by AnimalMonster; 08-08-2021 at 21:29.
AnimalMonster is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-08-2021 , 21:48   Re: Detect when a entity passes through anything a map has
Reply With Quote #2

Hook touch?
__________________
Bugsy is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 08-08-2021 , 22:00   Re: Detect when a entity passes through anything a map has
Reply With Quote #3

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
__________________
My plugin:

Last edited by Celena Luna; 08-08-2021 at 22:01.
Celena Luna is offline
AnimalMonster
Senior Member
Join Date: May 2020
Old 08-08-2021 , 22:13   Re: Detect when a entity passes through anything a map has
Reply With Quote #4

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

Last edited by AnimalMonster; 08-08-2021 at 22:20.
AnimalMonster is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-08-2021 , 22:24   Re: Detect when a entity passes through anything a map has
Reply With Quote #5

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 );

__________________

Last edited by Bugsy; 08-08-2021 at 22:26.
Bugsy is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-09-2021 , 08:52   Re: Detect when a entity passes through anything a map has
Reply With Quote #6

Its every important to check entities validity in the touch function because its called many times depending on player frame per second
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 08-09-2021 at 08:53.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
DJEarthQuake
Veteran Member
Join Date: Jan 2014
Location: Astral planes
Old 08-09-2021 , 09:22   Re: Detect when a entity passes through anything a map has
Reply With Quote #7

Quote:
Originally Posted by AnimalMonster View Post
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!
__________________

Last edited by DJEarthQuake; 08-09-2021 at 09:27.
DJEarthQuake is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-09-2021 , 10:44   Re: Detect when a entity passes through anything a map has
Reply With Quote #8

Quote:
Originally Posted by AnimalMonster View Post
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.
__________________

Last edited by HamletEagle; 08-09-2021 at 10:54.
HamletEagle is offline
AnimalMonster
Senior Member
Join Date: May 2020
Old 09-04-2021 , 20:29   Re: Detect when a entity passes through anything a map has
Reply With Quote #9

Quote:
Originally Posted by HamletEagle View Post
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)

Last edited by AnimalMonster; 09-04-2021 at 20:31.
AnimalMonster is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 09-05-2021 , 09:22   Re: Detect when a entity passes through anything a map has
Reply With Quote #10

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. View Post
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[].
__________________









Last edited by CrazY.; 09-05-2021 at 10:08.
CrazY. is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:59.


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