6th Aug 2003, 11:03 PM  #1 
Registered User
Join Date: Feb. 20th, 2003
Posts: 128

More vector math [sorry :P]
What I basically need is an absolute value type function for a vector. Not true abs, but something that does the same thing:
I have some actor, which is facing some direction. If you shoot the actor from the side, the momentum conitues along through the side. If you shoot from the back, the momentum, again, doesn't change and carries through the back to the front. If you shoot the actor from the backside, again, nothing happens to it. BUT, if you shoot the actor from the front, I want the inverse of the vector. If you shoot the actor from the frontside, you get the momentum as if it where shot from the back through the same side. I've been wracking my brains, and all the documentation on uscript vector functions, and haven't been able to come up with anything that works. So once more, I plead to the local mathgods for some muchneeded help. Thanks! [The question of offset was solved using a creative take on the GetAxes function; not sure if it was proper, but it worked. This abs thing is still an issue through :P] Last edited by Dryn; 7th Aug 2003 at 03:00 AM. 
7th Aug 2003, 09:00 PM  #2 
Something like this?
__________________
"He who breaks a thing to find out what it is, has left the path of wisdom."  Gandalf the GrayHat 

7th Aug 2003, 09:46 PM  #3 
Code:
if (normal(momentum) dot vector(hitthing.rotation) < 0) momentum*=1; 

7th Aug 2003, 10:32 PM  #4 
Registered User
Join Date: Feb. 20th, 2003
Posts: 128

Nice diagram, first off ... Thats exactly what I meant, but with pretty shapes and colors!
As for the code snippet there, the check is right (thx) but the inversion code is not the ABS thing, which is the problem... Still haven't found a way to implement that, so if anyone has any more ideas, it would be greatly appreciated! 
7th Aug 2003, 11:17 PM  #5  
Quote:
What you want to do is REFLECT the vector off the plane. To do this your do something like this: Find the normal vector of the plane of reflection Project the impact vector onto the normal vector subtract the projected vector from the impact vector, producing the impact vector projected onto the reflection plane subtract it again, pulling it to the other side of the reflection plane, thus reflecting the vector off the reflection plane. so, off the top of my head and without a syntax check... Code:
simulated function vector ReflectVector(vector source, vector normal) { local float length; local vector projected; // probaby not needed: normal = Normal(normal); // find the length of the projected vector (works because normal is a unit vector) length = normal dot source; // find the projected vector (again, normal is a unit vector) projected = length * normal; // subtract the normal from the impact vector twice. return source  2*projected; }
__________________
"He who breaks a thing to find out what it is, has left the path of wisdom."  Gandalf the GrayHat 

9th Aug 2003, 01:17 AM  #6 
So does it work?
__________________
"He who breaks a thing to find out what it is, has left the path of wisdom."  Gandalf the GrayHat 

9th Aug 2003, 04:42 PM  #7 
Registered User
Join Date: Feb. 20th, 2003
Posts: 128

...
Not sure yet; This seems to be working, after a little work, but I'm having a hard time finding out if I'm using the proper reflection normal.
I will post the working code once its ready. Last edited by Dryn; 9th Aug 2003 at 04:58 PM. 
9th Aug 2003, 05:26 PM  #8 
Registered User
Join Date: Feb. 20th, 2003
Posts: 128

Code:
if(normal(momentum) dot ReflectionNormal < 0) { // find the length of the projected vector (works because normal is a unit vector) length = ReflectionNormal dot Momentum; // find the projected vector (again, normal is a unit vector) projected = length * ReflectionNormal; // subtract the normal from the impact vector twice. Momentum = 2*projected; } (perhaps we should stick this on the wiki somewhere?) Last edited by Dryn; 9th Aug 2003 at 05:27 PM. 
9th Aug 2003, 05:46 PM  #9 
you don't need to normalize momemtum for the first dot product  all you want is the sign.
__________________
"He who breaks a thing to find out what it is, has left the path of wisdom."  Gandalf the GrayHat 

9th Aug 2003, 06:20 PM  #10  
Join Date: Oct. 3rd, 2001
Location: Frankfurt/Main, Germany
Posts: 3,829

Quote:


Thread Tools  
Display Modes  

