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

TraceRay Help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Skippy
Senior Member
Join Date: Nov 2011
Old 12-29-2015 , 02:34   TraceRay Help
Reply With Quote #1

This is my situation. I need to be able to detect if someone is looking 300 units within a small box that is in midair (Doesn't have to look right at it). The problem is that with traceray I'm only able to find the end point and if someone isn't directly looking at the small box then they are looking at a wall way past the box. I need to be able to consider every point on the traceray and determine if someone's eye sight is within 300 units (creates a sphere) around the box.
__________________
Plugins:
[Any] Aim Menu

Want a TF2 plugin? Feel free to pm me to discuss it.
Skippy is offline
thecount
Veteran Member
Join Date: Jul 2013
Old 12-29-2015 , 13:07   Re: TraceRay Help
Reply With Quote #2

I'm not sure about checking every point on the ray as that is not feasible. Someone else might have a better idea, but the only way I can think of to use TraceRay functionality is to make a sphere prop the size you want and invisible with no collision to players. Hopefully the traceray will still hit it regardless of its collision.

Actually, you could grab the forward vector of where the player is looking and do some math to find where this ray would be on certain points of the sphere then compare the distance from that point to the center of the sphere. I can't seem to think of an efficient way to solve this problem.

Last edited by thecount; 12-29-2015 at 13:11.
thecount is offline
Skippy
Senior Member
Join Date: Nov 2011
Old 12-29-2015 , 13:21   Re: TraceRay Help
Reply With Quote #3

Quote:
Originally Posted by thecount View Post
I'm not sure about checking every point on the ray as that is not feasible. Someone else might have a better idea, but the only way I can think of to use TraceRay functionality is to make a sphere prop the size you want and invisible with no collision to players. Hopefully the traceray will still hit it regardless of its collision.

Actually, you could grab the forward vector of where the player is looking and do some math to find where this ray would be on certain points of the sphere then compare the distance from that point to the center of the sphere. I can't seem to think of an efficient way to solve this problem.
That's the thing. I don't know how to find the points along the whole traceray. I can only find the end point.
__________________
Plugins:
[Any] Aim Menu

Want a TF2 plugin? Feel free to pm me to discuss it.
Skippy is offline
thecount
Veteran Member
Join Date: Jul 2013
Old 12-29-2015 , 23:52   Re: TraceRay Help
Reply With Quote #4

Well if you have the direction of the ray, you could use that ratio of x:y:z to find a the value of a coordinate at a specific point. Say the direction of the ray is 2:7:5 and the distance on each axis from the player to a specific point you're checking is 3:4:6... You could check where the ray is when the x coordinate is 3 by 7 / 2 * 3 = Y coord and 5 / 2 * 3 = Z coord. The problem then would be deciding which coordinates to check. You could pick the greatest and least X value the 'sphere' contains and then once you calculate the position of the ray at that point, you can then check if it is indeed inside the sphere. But more than likely on these greater/least coordinates, the ray will be outside the sphere. So maybe use coordinates of a smaller radius inside, and then check if the ray point is inside the larger sphere. That probably wasn't a very clear explanation of what I mean. I'm using some similar logic for aiming in my C++ project, which is why I have given this some thought.

Last edited by thecount; 12-29-2015 at 23:57.
thecount is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 12-30-2015 , 00:45   Re: TraceRay Help
Reply With Quote #5

PHP Code:
bool f(int client, const float boxpos[3])
{
    
float a[3], b[3], dir[3],  ang[3], diff[3], p[3], vec[3];
    
GetClientAbsOrigin(clienta);
    
GetClientEyeAngles(clientang);
    
GetAngleVectors(angdirNULL_VECTORNULL_VECTOR);
    
    
a;
    
vec dir;
    
ScaleVector(vec10000.0);
    
AddVectors(bvecb);
    
    
SubtractVectors(badiff);
    
    
float lsq GetVectorLength(difftrue);
    
    
SubtractVectors(boxposavec);
    
float t GetVectorDotProduct(vecdiff) / lsq;
    
    if (
0)
        
0.0;
    else if (
1)
        
1.0;
    
    
vec diff;
    
ScaleVector(vect);
    
AddVectors(avecp);
    
    
SubtractVectors(pboxposp);
    return 
GetVectorLength(p) < 300;

something like that

Last edited by Miu; 12-30-2015 at 00:55.
Miu is offline
thecount
Veteran Member
Join Date: Jul 2013
Old 12-30-2015 , 01:34   Re: TraceRay Help
Reply With Quote #6

Quote:
Originally Posted by Miu View Post
something like that
Yeah, that seems like it should work. Nifty vector functions. The boxpos[3] parameter should actually be the center of it, I believe. Just in case you're using a prop that is not centered on the origin.

Last edited by thecount; 12-30-2015 at 01:55.
thecount is offline
Skippy
Senior Member
Join Date: Nov 2011
Old 12-30-2015 , 03:29   Re: TraceRay Help
Reply With Quote #7

Quote:
Originally Posted by Miu View Post
PHP Code:
bool f(int client, const float boxpos[3])
{
    
float a[3], b[3], dir[3],  ang[3], diff[3], p[3], vec[3];
    
GetClientAbsOrigin(clienta);
    
GetClientEyeAngles(clientang);
    
GetAngleVectors(angdirNULL_VECTORNULL_VECTOR);
    
    
a;
    
vec dir;
    
ScaleVector(vec10000.0);
    
AddVectors(bvecb);
    
    
SubtractVectors(badiff);
    
    
float lsq GetVectorLength(difftrue);
    
    
SubtractVectors(boxposavec);
    
float t GetVectorDotProduct(vecdiff) / lsq;
    
    if (
0)
        
0.0;
    else if (
1)
        
1.0;
    
    
vec diff;
    
ScaleVector(vect);
    
AddVectors(avecp);
    
    
SubtractVectors(pboxposp);
    return 
GetVectorLength(p) < 300;

something like that
Yes!! Thank you so much. That worked perfectly.
__________________
Plugins:
[Any] Aim Menu

Want a TF2 plugin? Feel free to pm me to discuss it.
Skippy 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 19:15.


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