AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Calculate trajectory and point of exit (https://forums.alliedmods.net/showthread.php?t=154938)

Hunter-Digital 04-15-2011 14:21

Calculate trajectory and point of exit
 
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 :}

bibu 04-15-2011 14:53

Re: Calculate trajectory and point of exit
 
I don't know if this can be useful:

http://forums.alliedmods.net/showthread.php?p=910208

Hunter-Digital 04-15-2011 21:14

Re: Calculate trajectory and point of exit
 
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

Exolent[jNr] 04-15-2011 22:18

Re: Calculate trajectory and point of exit
 
It's really not that hard.
You just need to make sure the trace hits a wall, then reflect the direction off the wall.

Hunter-Digital 04-15-2011 22:24

Re: Calculate trajectory and point of exit
 
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 :/

Exolent[jNr] 04-15-2011 23:03

Re: Calculate trajectory and point of exit
 
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.

Hunter-Digital 04-15-2011 23:40

Re: Calculate trajectory and point of exit
 
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)

Exolent[jNr] 04-16-2011 01:00

Re: Calculate trajectory and point of exit
 
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 );

Hunter-Digital 04-16-2011 13:13

Re: Calculate trajectory and point of exit
 
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 ? :-?

Exolent[jNr] 04-16-2011 17:43

Re: Calculate trajectory and point of exit
 
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


All times are GMT -4. The time now is 20:11.

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