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

Calculate trajectory and point of exit


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 04-15-2011 , 14:21   Calculate trajectory and point of exit
Reply With Quote #1

Basically, I want to send bullets from one place to another while keeping the relative position and angles of trajectory...

So, what I have for now is Ham_TraceAttack hooked, I'm checking if the ending shot location was at least 20 units away from my defined location and I'm redirecting that shot with new angles... but I need to calculate exacly where in those 20 units the shot got in and make it relatively exit the same position and with the same relative trajectory.

If this isn't understandable, I'll just post a screenshot, I can't now :}
__________________
Hunter-Digital is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 04-15-2011 , 14:53   Re: Calculate trajectory and point of exit
Reply With Quote #2

I don't know if this can be useful:

http://forums.alliedmods.net/showthread.php?p=910208
bibu is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 04-15-2011 , 21:14   Re: Calculate trajectory and point of exit
Reply With Quote #3

I don't get much from that :/ xs_* functions confuse me.

Still, I think I'll need a better "hit" detection first, something more concrete than range checking for hits on walls xD
__________________
Hunter-Digital is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-15-2011 , 22:18   Re: Calculate trajectory and point of exit
Reply With Quote #4

It's really not that hard.
You just need to make sure the trace hits a wall, then reflect the direction off the wall.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 04-15-2011 , 22:24   Re: Calculate trajectory and point of exit
Reply With Quote #5

I don't want to reflect it from the same wall, I want it to be continued somewhere else.

To be more exact, this is for the portal project I'm continuing to work on... if you shoot a portal it gets out somewhere else and the other portal can be on the same wall, on a floor, on a ceiling, on a slope so it's tricky xD

Currently the shot only exits the portal directly from the center of it and goes straight, no matter the angles or position where you shot the first portal :/
__________________
Hunter-Digital is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-15-2011 , 23:03   Re: Calculate trajectory and point of exit
Reply With Quote #6

Okay, then what you could do is take the normal of the 2 walls, and get the angle between them.
Then, you can transpose that angle from the original trajectory to calculate the new one.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 04-15-2011 , 23:40   Re: Calculate trajectory and point of exit
Reply With Quote #7

Well, I have the normal and the angles of both walls (barely xD) but I can't get the exit angle right... what do you mean transpose ? O.o can you give me an example using two angles or directional vectors ? (I have both)
__________________
Hunter-Digital is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-16-2011 , 01:00   Re: Calculate trajectory and point of exit
Reply With Quote #8

Something like this:
Code:
#include <amxmodx> #include <xs> XS_LIBFUNC_ATTRIB xs_vec_anglevector(const Float:vecPair1[3], const Float:vecPair2[3], const Float:vecOther[3], Float:vecResult[3]) {     new Float:vecAngles1[ 3 ], Float:vecAngles2[ 3 ];     vector_to_angle( vecPair1, vecAngles1 );     vector_to_angle( vecPair2, vecAngles2 );         new Float:vecAngleDiff[ 3 ];     xs_vec_sub( vecAngles2, vecAngles1, vecAngleDiff );         vector_to_angle( vecOther, vecAngles1 );         xs_vec_add( vecAngles1, vecAngleDiff, vecAngles2 );         angle_vector( vecAngles2, ANGLEVECTOR_FORWARD, vecResult ); }
vecPair1 would be the normal for the first wall
vecPair2 would be the direction towards the first wall
vecOther would be the normal for the second wall
vecResult would be the calculated direction for the second wall

You would need to change the direction towards the first wall to be backwards (away from the wall instead of towards it) before you did this function.
Or you could reverse the result.

Example:

Code:
new Float:vecNormal1[ 3 ], Float:vecDirection1[ 3 ], Float:vecNormal2[ 3 ] // your initial vectors that you need new Float:vecDirection2[ 3 ]; xs_vec_anglevector( vecNormal1, vecDirection1, vecNormal2, vecDirection2 ); // reverse direction xs_vec_neg( vecDirection2, vecDirection2 );
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 04-16-2011 , 13:13   Re: Calculate trajectory and point of exit
Reply With Quote #9

Hmm, I have the angle of the wall stored so I'm skipping the wall normal inputs... and I've come to this...
If the 2nd portal is on the floor or ceiling, it goes straight O.o
The angles are right btw, because in straight line they go just fine on ANY surface.


EDIT: lol fail, I used fDir directly in xs_vec_sub() instead of making it into an angle =) anyway, it works verry nicely XD thanks.

Now for the next issue... it needs to exit the same relative position it entered... but for that I need to first remake the hit detection system.
I think I'll make a new thin solid entity the size of that sprite and get hit detection on it... or is it possible to do it on sprites ? :-?
__________________

Last edited by Hunter-Digital; 04-16-2011 at 17:31.
Hunter-Digital is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-16-2011 , 17:43   Re: Calculate trajectory and point of exit
Reply With Quote #10

Relative position is easy as well.

Code:
new Float:vecOrigin1[ 3 ], Float:vecSprite1[ 3 ], Float:vecNormal1[ 3 ]; // player origin, the center of the portal sprite, and the normal of the wall new Float:vecSprite2[ 3 ], Float:vecNormal2[ 3 ]; // the center of the exit portal sprite, and the normal of the other wall new Float:vecDirection[ 3 ]; xs_vec_sub( vecOrigin1, vecSprite1, vecDirection ); xs_vec_anglevector( vecNormal1, vecDirection, vecNormal2, vecDirection ); new Float:vecOrigin2[ 3 ]; xs_vec_add( vecSprite2, vecDirection, vecOrigin2 ); // vecOrigin2 is the position of player outside of the portal relative to being outside the first portal
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 04-17-2011 at 04:40.
Exolent[jNr] 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 07:28.


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