Results 1 to 10 of 10

Thread: Math Problem

  1. #1
    MSgt. Shooter Person
    Join Date
    Apr 2010
    Posts
    43

    Default Math Problem

    I've got a question for all the math/trig geniuses.

    I am attempting to achieve an accurate reflection of velocity when my pawn contacts a surface (angled surfaces included).

    I am getting the normal of what i contact.
    Code:
    cNorm=HitNormal.X;
    set the new velocity variables to use when getting the angle..
    Code:
    veloX = Velocity.X;
    veloZ = Velocity.Z;
    then I'm converting my velocity to an angle in radians, and then converting that to degrees(for testing)..
    Code:
    angleInRadians = atan2 (veloZ, veloX);
    angleInDegrees = angleInRadians * 180 / PI;
    then multiplying the normal by 2 and subtracting the angle to get the new reflected angle and turn it back into a radian..
    Code:
    nAng = cNorm*2-angleInDegrees;
    nRad = nAng*PI/180;
    I can not find a way to convert radians back into velocity.. so I am trying to get the new reflected velocity from the angle in degrees..
    Code:
    V = Sqrt((veloX*veloX)+(veloZ*veloZ));
    velocx= cos(nAng)*V;
    velocZ = Sqrt((V*V)-(veloX*veloX));
    Finally I set the pawns velocity to equal the new reflected velocity.
    Code:
    Velocity.Z=velocZ;
    Velocity.X=velocX;

    I am doing something wrong and often get sporadic results..if anyone sees where I am going astray please help by pointing it out or how I should go about doing it.

    thank you,
    -Dying

  2. #2

    Default

    Are we talking about in=out angles? In that case you might want to try:
    Code:
    Velocity = MirrorVectorByNormal(Velocity, HitNormal);
    If you want to factor in dampening, the UT games use variations of the following formula:
    Code:
        VNorm = (Velocity dot HitNormal) * HitNormal;
        Velocity = -VNorm * DampenFactor + (Velocity - VNorm) * DampenFactorParallel;
    The MirrorVectorByNormal function basically does that calculation with the two dampening factors being 1.
    Wormbo's UT/UT2004/UT3 mods | PlanetJailbreak | Unreal Wiki | Liandri Archives

    <elmuerte> you shouldn't do all-nighters, it's a waste of time and effort
    <TNSe> nono
    <TNSe> its always funny to find code a week later you dont even remember writing
    <Pfhoenix> what's worse is when you have a Star Wars moment
    <Pfhoenix> "Luke! I am your code!" "No! Impossible! It can't be!"
    Note that your questions via PMs will be ignored if they actually belong in the forum.

  3. #3
    MSgt. Shooter Person
    Join Date
    Apr 2010
    Posts
    43

    Default

    Wow I did not know unreal had this! thank you so much wormbo, this saves me alot of time and headaches

  4. #4
    MSgt. Shooter Person
    Join Date
    Apr 2010
    Posts
    43

    Default

    hmm wondering if anyone knows why when the angle im bouncing off of is over 60 degrees(so unreal reads it as a wall) the new reflection doesn bounce off correctly.. if the angle is 90 degrees the pawn doesnt bounce off at all, it actually stops and floats up..?

  5. #5
    Iron Guard
    Join Date
    May 2010
    Location
    UK
    Posts
    662

    Default

    Quote Originally Posted by Wormbo View Post
    Are we talking about in=out angles? In that case you might want to try:
    Code:
    Velocity = MirrorVectorByNormal(Velocity, HitNormal);
    Oh god, I didn't see this, so I had to make it on my own. :P

    Code:
    /** Vector reflection of a based on normal vector b*/
    function vector rV(Vector a, vector b){
    	return 2 * (-a.x * b.x + -a.y * b.y + -a.z * b.z) * b + a;
    }
    Project Aron is now recruiting (experienced programmers)!
    My website!

  6. #6
    MSgt. Shooter Person
    Join Date
    Apr 2010
    Posts
    43

    Default

    hey toxicFork have you ever had a similar problem where this formula doesn't work if the Normal.X is between 60 to 90 degrees?

  7. #7

    Default

    You really should have looked up available operators and functions.
    UnrealWiki: Vector sums up the built-in vector operations, in case you need more.
    Wormbo's UT/UT2004/UT3 mods | PlanetJailbreak | Unreal Wiki | Liandri Archives

    <elmuerte> you shouldn't do all-nighters, it's a waste of time and effort
    <TNSe> nono
    <TNSe> its always funny to find code a week later you dont even remember writing
    <Pfhoenix> what's worse is when you have a Star Wars moment
    <Pfhoenix> "Luke! I am your code!" "No! Impossible! It can't be!"
    Note that your questions via PMs will be ignored if they actually belong in the forum.

  8. #8
    Iron Guard
    Join Date
    May 2010
    Location
    UK
    Posts
    662

    Default

    Dying, I don't know, it worked pretty well for me.
    Normal.X isn't in degrees btw, paste your code so we can see what's going wrong
    Project Aron is now recruiting (experienced programmers)!
    My website!

  9. #9

    Default

    Well, if you really want to see an angle in a normal vector component, then Normal.X is the cosine of the normal's angle from the YZ plane. For reflections this is an absolutely useless piece of information, though.
    Wormbo's UT/UT2004/UT3 mods | PlanetJailbreak | Unreal Wiki | Liandri Archives

    <elmuerte> you shouldn't do all-nighters, it's a waste of time and effort
    <TNSe> nono
    <TNSe> its always funny to find code a week later you dont even remember writing
    <Pfhoenix> what's worse is when you have a Star Wars moment
    <Pfhoenix> "Luke! I am your code!" "No! Impossible! It can't be!"
    Note that your questions via PMs will be ignored if they actually belong in the forum.

  10. #10
    MSgt. Shooter Person
    Join Date
    Apr 2010
    Posts
    43

    Default

    ah i figured out my problem, I was only applying the new velocity to the Z velocity when hitting a wall and not the X..

    thanks guys, you got my project back on its way to completion


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.