Raised This Month: $ Target: $400
 0% 

Detecting other player's movement direction


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 01-01-2014 , 14:51   Re: Detecting other player's movement direction
Reply With Quote #7

Quote:
Originally Posted by StaticDude View Post
Yeah, detecting other directions is also needed. I'll try to explain it better: I need to detect in which way player moves on my screen (left/right/up/down/left&up/left&down and etc).
I don't have time to make code for you but what I would do would be:

1 - Create a plane based on the position of your eyes and your view angle.
2 - Push the enemy current origin and previous origin to your plane, that will give you two vectors on your plane.
3 - Subtract them (current-previous) and you will have a vector that points the previous from the current relative to your plane.
4 - Now what you want is the angle of that vector in your plane.

With include xs help:

1 -
Code:
// Construct a plane out of 3 points
    // tested
    XS_LIBFUNC_ATTRIB xs_plane_3p(Float:plane[], const Float:p1[], const Float:p2[], const Float:p3[])
This function constructs a plane with three points.
The three points you can get them from:

Code:
XS_LIBFUNC_ATTRIB xs_anglevectors(const Float:angles[3], Float:fwd[3], Float:right[3], Float:up[3])
Pass to that function your viewangles, get your fwd,right an up, and add to those three vector the origin of your eyes. Then create a plane with those three vectors.

2 -
Code:
XS_LIBFUNC_ATTRIB xs_projpoint_onplane(const Float:plane[], const Float:point[], Float:out[])
3 -
Code:
XS_LIBFUNC_ATTRIB xs_vec_sub(const Float:in1[], const Float:in2[], Float:out[])
4 - My solution to this part is a bit trickier.
As the last vector you got is relative to your plane, you can define it over the fwd and right vectors you got from xs_anglevectors (before adding eyes origin to them) like

α * fwd + β * right = vector
α *(a,b,c) + β*(d,e,f) = (x,y,z)

This gives you three equations (remember you are just missing α and β):

aα + βd = x
bα + βe = y
cα + βf = z

You solve them and you got α and β.
Now, you have the 2D vector (α,β) that is what you want. Remember that you can then also calculate the angle of this 2D vector with normal trigonometric functions.
__________________

Last edited by joaquimandrade; 01-01-2014 at 14:55.
joaquimandrade is offline
 



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 15:26.


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