News UnrealEd Files Mods FragBU Liandri Archives
BeyondUnreal Forums

Go Back   BeyondUnreal Forums > Unreal Development > Coding

Reply
 
Thread Tools Display Modes
Old 6th Aug 2003, 11:03 PM   #1
Dryn
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 back-side, 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 front-side, 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 math-gods for some much-needed 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.
Dryn is offline   Reply With Quote
Old 7th Aug 2003, 09:00 PM   #2
inio
many fauceted scarlet emerald
 
inio's Avatar
 
Join Date: Feb. 8th, 2002
Location: CA, USA
Posts: 105
Something like this?

__________________
"He who breaks a thing to find out what it is, has left the path of wisdom."
- Gandalf the Gray-Hat
inio is offline   Reply With Quote
Old 7th Aug 2003, 09:46 PM   #3
usaar33
Un1337
 
usaar33's Avatar
 
Join Date: Mar. 25th, 2000
Location: Unknown
Posts: 808
Code:
if (normal(momentum) dot vector(hitthing.rotation) < 0)
   momentum*=-1;
usaar33 is offline   Reply With Quote
Old 7th Aug 2003, 10:32 PM   #4
Dryn
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!
Dryn is offline   Reply With Quote
Old 7th Aug 2003, 11:17 PM   #5
inio
many fauceted scarlet emerald
 
inio's Avatar
 
Join Date: Feb. 8th, 2002
Location: CA, USA
Posts: 105
Quote:
Originally Posted by Dryn
Nice diagram
Thanks.

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 Gray-Hat
inio is offline   Reply With Quote
Old 9th Aug 2003, 01:17 AM   #6
inio
many fauceted scarlet emerald
 
inio's Avatar
 
Join Date: Feb. 8th, 2002
Location: CA, USA
Posts: 105
So does it work?
__________________
"He who breaks a thing to find out what it is, has left the path of wisdom."
- Gandalf the Gray-Hat
inio is offline   Reply With Quote
Old 9th Aug 2003, 04:42 PM   #7
Dryn
Registered User
 
Join Date: Feb. 20th, 2003
Posts: 128
Post ...

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.
Dryn is offline   Reply With Quote
Old 9th Aug 2003, 05:26 PM   #8
Dryn
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;
}
This is it, and it works like a charm. Thanks!

(perhaps we should stick this on the wiki somewhere?)

Last edited by Dryn; 9th Aug 2003 at 05:27 PM.
Dryn is offline   Reply With Quote
Old 9th Aug 2003, 05:46 PM   #9
inio
many fauceted scarlet emerald
 
inio's Avatar
 
Join Date: Feb. 8th, 2002
Location: CA, USA
Posts: 105
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 Gray-Hat
inio is offline   Reply With Quote
Old 9th Aug 2003, 06:20 PM   #10
Mychaeel
 
Join Date: Oct. 3rd, 2001
Location: Frankfurt/Main, Germany
Posts: 3,829
Quote:
Originally Posted by Dryn
(perhaps we should stick this on the wiki somewhere?)
Stick it on Unreal Wiki: UnrealScript Vector Maths.
Mychaeel is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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 -5. The time now is 04:54 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.

Copyright ©1998 - 2012, BeyondUnreal, Inc.
Privacy Policy | Terms of Use
Bandwidth provided by AtomicGamer