More vector math [sorry :P]

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

Dryn

New Member
Feb 20, 2003
128
0
0
Visit site
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:

inio

many fauceted scarlet emerald
Feb 8, 2002
105
0
0
CA, USA
www.inio.org
Something like this?

onewaymirror.gif
 

Dryn

New Member
Feb 20, 2003
128
0
0
Visit site
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!
 

inio

many fauceted scarlet emerald
Feb 8, 2002
105
0
0
CA, USA
www.inio.org
Dryn said:
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;
}
 

Dryn

New Member
Feb 20, 2003
128
0
0
Visit site
...

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:

Dryn

New Member
Feb 20, 2003
128
0
0
Visit site
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: