1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. 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.

More vector math [sorry :P]

Discussion in 'Programming' started by Dryn, Aug 6, 2003.

  1. Dryn

    Dryn New Member

    Joined:
    Feb 20, 2003
    Messages:
    128
    Likes Received:
    0
    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: Aug 7, 2003
  2. inio

    inio many fauceted scarlet emerald

    Joined:
    Feb 8, 2002
    Messages:
    105
    Likes Received:
    0
    Something like this?

    [​IMG]
     
  3. usaar33

    usaar33 Un1337

    Joined:
    Mar 25, 2000
    Messages:
    808
    Likes Received:
    0
    Code:
    if (normal(momentum) dot vector(hitthing.rotation) < 0)
       momentum*=-1;
    
     
  4. Dryn

    Dryn New Member

    Joined:
    Feb 20, 2003
    Messages:
    128
    Likes Received:
    0
    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!
     
  5. inio

    inio many fauceted scarlet emerald

    Joined:
    Feb 8, 2002
    Messages:
    105
    Likes Received:
    0
    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;
    }
     
  6. inio

    inio many fauceted scarlet emerald

    Joined:
    Feb 8, 2002
    Messages:
    105
    Likes Received:
    0
    So does it work?
     
  7. Dryn

    Dryn New Member

    Joined:
    Feb 20, 2003
    Messages:
    128
    Likes Received:
    0
    ...

    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: Aug 9, 2003
  8. Dryn

    Dryn New Member

    Joined:
    Feb 20, 2003
    Messages:
    128
    Likes Received:
    0
    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: Aug 9, 2003
  9. inio

    inio many fauceted scarlet emerald

    Joined:
    Feb 8, 2002
    Messages:
    105
    Likes Received:
    0
    you don't need to normalize momemtum for the first dot product - all you want is the sign.
     
  10. Mychaeel

    Mychaeel New Member

    Joined:
    Oct 3, 2001
    Messages:
    3,830
    Likes Received:
    0

Share This Page