Raised This Month: $ Target: $400
 0% 

Box collision/distance functions


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Kraugh
Senior Member
Join Date: Jan 2006
Location: barrington, ri
Old 03-02-2006 , 01:49   Box collision/distance functions
Reply With Quote #1

original code is from the HLSDK (UTIL_EntitiesInBox). you can use these functions to determine if two entities are touching each other. i'm not going to explain what you can use this for.

functions are as follows:

find_ent_in_box ( StartEntity, Float:mins[3], Float:maxs[3] )
Code:
// PARAMETERS
// -
// StartEntity:	which entity to start searching from
// mins:	the absmin of your collision box
// maxs:	the absmax of your collision box
//
//
// RETURN VALUES
// -
// returns the index of the first entity found.
// if no entities were found this returns 0.
find_box_list ( Float:mins[3], Float:maxs[3], entlist[], maxents, param[] = "", type = 0 )
Code:
// PARAMETERS
// -
// mins:	the absmin of your collision box
// maxs:	the absmax of your collision box
// entlist:	array to store entities found in
// maxents:	maximum amount of entities to store
// param:	(optional, default "") the string to compare collisions with (see below). if blank, ignored.
// type:	(optional, default 0)  0: find by classname, 1: find by target, 2: find by targetname
//
//
// RETURN VALUES
// -
// returns the amount of entities saved into entlist
check_collision ( entity1, entity2 )
Code:
// PARAMETERS
// -
// entity1:	the first entity to compare
// entity2:	the second entity to compare
//
//
// RETURN VALUES
// -
// returns 1 if the two entities collide, otherwise 0.
check_collision_ext ( StartEntity, entity, param[], type = 0 )
Code:
// PARAMETERS
// -
// StartEntity:	which entity to start searching from
// entity:	the entity of which to check collisions for
// param:	the string to compare collisions with (see below)
// type:	(optional, default 0) 0: find by classname, 1: find by target, 2: find by targetname
//
//
// RETURN VALUES
// -
// returns the index of the first colliding entity found with the matching field.
// if no valid entities were found this returns 0.
Float: get_box_distance ( Float:mins1[3], Float:maxs1[3], Float:mins2[3], Float:maxs2[3] )
Code:
*    PARAMETERS:
*        mins1 - mins of the first  box, Float:{min_x1, min_y1, min_z1}
*        maxs1 - maxs of the first  box, Float:{max_x1, max_y1, max_z1}
*        mins2 - mins of the second box, Float:{min_x2, min_y2, min_z2}
*        maxs2 - maxs of the second box, Float:{max_x2, max_y2, max_z2}
*
*    RETURN RESULT:
*        Float value of distance between first and second box.
*        If result is 0.0 then boxes are colliding/touching.
requires engine. find_ent_in_box as well as find_box_list is not tested (sorry) but i see no reason why they shouldn't work. check_collision_ext (and thus check_collision) works marvelously. this does work if two entities are touching (ie: if you walk up to a hostage), aka they do not have to be actually overlapping.

feel free to make suggestions. you don't have to use the include, you can just copy out the functions. check_collision_ext requires check_collision to work.

get_box_distance written by VEN.
Attached Files
File Type: inc box.inc (6.3 KB, 267 views)
__________________
"You can not restrain a fool from speaking, but nothing obliges you to listen."
Kraugh is offline
Send a message via AIM to Kraugh
 



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 20:19.


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