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

Detect client collision with wall


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
BlacKisEverywhere
Junior Member
Join Date: Feb 2020
Old 07-17-2020 , 14:03   Detect client collision with wall
Reply With Quote #1

Hello.

My code looks like that:
PHP Code:
public bool IsClientColideWithWall(int client){
    
float pos[3];
    
GetClientEyePosition(clientpos);

    
float angles[3];
    
float endPos[3];
    
float distance;

    
Handle trace;

    
bool nearWall false;

    for(
int angle 0angle 360angle+= 30){
        
angles[0] = 0.0;
        
angles[1] = float(angle);
        
angles[2] = 0.0;

        
trace TR_TraceRayFilterEx(posanglesMASK_SOLIDRayType_InfiniteTraceFilterclient);

        if(
TR_DidHit(trace)){
            
TR_GetEndPosition(endPostrace);

            
distance GetVectorDistance(endPospostrue);

            if(
distance 5)
                
nearWall true;
        }

        
CloseHandle(trace);
    }
    return 
nearWall;
}

public 
bool TraceFilter(int entityint maskany data) {
    if(
entity == data)
        return 
false;
    return 
true;

This code everytime returns FALSE, but when i deleted TraceFilter function and changed tray function for TR_TraceRayEx code starts returning TRUE
BlacKisEverywhere is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 07-17-2020 , 14:12   Re: Detect client collision with wall
Reply With Quote #2

Tracehull should be what you want. It uses the player's physical body as the ray. From there add a single unit along the current angle to test if it collides.

Don't forget that this will affect inclines, which means you need to account for stepsize. Which I don't know how to do
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
BlacKisEverywhere
Junior Member
Join Date: Feb 2020
Old 07-17-2020 , 15:53   Re: Detect client collision with wall
Reply With Quote #3

Quote:
Originally Posted by eyal282 View Post
Tracehull should be what you want. It uses the player's physical body as the ray. From there add a single unit along the current angle to test if it collides.

Don't forget that this will affect inclines, which means you need to account for stepsize. Which I don't know how to do
I changed my code to:
PHP Code:
public bool IsClientColideWithWall(int client){
    
float pos[3];
    
GetClientAbsOrigin(clientpos);

    
float angles[3];
    
GetClientAbsAngles(clientangles)

    
float min[3] = { 0.10.10.1 };
    
float max[3] = { 10.010.010.0 };

    
Handle trace TR_TraceHullFilterEx(posanglesminmaxMASK_SOLIDTraceFilterclient);

    if(
TR_DidHit(trace)){
        
float endPos[3];
        
TR_GetEndPosition(endPostrace);
        
        
float distance GetVectorDistance(posendPos);

        
PrintToChat(client"[%0.1f]"distance);

        if(
distance <= 1){
            
CloseHandle(trace);
            return 
true;
        }
        
        
CloseHandle(trace);
        return 
false;
    }

    
CloseHandle(trace);
    return 
false;

and now when i go to the left wall i got low values like 16.0 but when i go to right wall i got high values like 400.00
BlacKisEverywhere is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 07-18-2020 , 10:14   Re: Detect client collision with wall
Reply With Quote #4

There's a native for getting a client's mins and maxs. Fix it for a start.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
BlacKisEverywhere
Junior Member
Join Date: Feb 2020
Old 07-18-2020 , 13:09   Re: Detect client collision with wall
Reply With Quote #5

Quote:
Originally Posted by eyal282 View Post
There's a native for getting a client's mins and maxs. Fix it for a start.
Ok, i changed my code for:
PHP Code:
public bool IsClientColideWithWall(int client){
    
float pos[3];
    
GetClientAbsOrigin(clientpos);
    
pos[2] += 50;

    
float min[3];
    
GetClientMins(clientmin);

    
float max[3];
    
GetClientMaxs(clientmax);

    
Handle trace TR_TraceHullFilterEx(posposminmaxMASK_SOLIDTraceFilterclient);

    if(
TR_DidHit(trace)){
        
float endPos[3];
        
TR_GetEndPosition(endPostrace);
        
        
HullTest(endPos);

        return 
true;
    }

    
CloseHandle(trace);
    return 
false;

HullTest func is just a test function which spawn chicken at hull hit position.
Now that function works but not for all walls.
BlacKisEverywhere is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 07-19-2020 , 04:10   Re: Detect client collision with wall
Reply With Quote #6

Your code checks if the player would be stuck if you teleported him upwards 50 units. The part of the angles in your previous code is likely necessary, although 5 degrees jump would be better to ensure full accuracy.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
BlacKisEverywhere
Junior Member
Join Date: Feb 2020
Old 07-19-2020 , 06:01   Re: Detect client collision with wall
Reply With Quote #7

Quote:
Originally Posted by eyal282 View Post
Your code checks if the player would be stuck if you teleported him upwards 50 units. The part of the angles in your previous code is likely necessary, although 5 degrees jump would be better to ensure full accuracy.
Thank you!!

PHP Code:
public bool IsClientColideWithWall(int client){
    
float pos[3];
    
GetClientAbsOrigin(clientpos);
    
pos[2] += 50;

    
float min[3];
    
GetClientMins(clientmin);

    
float max[3];
    
GetClientMaxs(clientmax);

    
min[0] -= 5;
    
min[1] -= 5;

    
max[0] += 5;
    
max[1] += 5;

    
Handle trace TR_TraceHullFilterEx(posposminmaxMASK_SOLIDTraceFilterclient);

    if(
TR_DidHit(trace))
        return 
true;
    
    
CloseHandle(trace);
    return 
false;

PHP Code:
public bool TraceFilter(int entityint maskany data){
    if(
entity == data)
        return 
false;
    return 
true;

That code works very well. You are my life saver.

Last edited by BlacKisEverywhere; 07-19-2020 at 06:03.
BlacKisEverywhere is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 07-19-2020 , 06:57   Re: Detect client collision with wall
Reply With Quote #8

Wait, this will return true if there is a wall above your head without exact collision. You should manipulate mins / maxs of height to deal with stepsize ( which defaults to 18, not 50 if I remember right ) instead of current position.

I am just unsure how mins works exactly. Also there should be a netprop for stepsize, as there is a cvar ( hidden ) for changing step size.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 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 10:30.


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