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.

[UT2004] Player Pawn Velocity being reset after Landed()

Discussion in 'Programming' started by mccann, May 24, 2004.

  1. mccann

    mccann New Member

    Joined:
    May 24, 2004
    Messages:
    18
    Likes Received:
    0
    I want a player to automatically bounce when shield gun is active.

    The problem is that I can't determine where the Pawn's Velocity is being zero'd out. I intercept the GameRules.NetDamage() method and minimize the damage, but I'm not sure how to bounce the player back in the air.

    Within the GameRules.NetDamage() method, I've tried things like:
    Code:
    injured.SetPhysics(PHYS_Falling);
    injured.Velocity = injured.Velocity *(vect(1,1,-0.5));
    injured.Velocity=JumpVelocity; //JumpVelocity=(Z=1200.000000)
    injured.bBounce=true;
    injured.bCanFly=True;
    injured.DoJump(true);
    
    ...etc...
    ... but it would appear that nothing that I've done to re-enable the Velocity in the other direction works. The Pawn's Landed() method doesn't change the Velocity, but it does modify the ImpactVelocity. Anyone know where I need to look? Or maybe a different way to approach this?

    Thanks in Advance!
     
  2. Dryn

    Dryn New Member

    Joined:
    Feb 20, 2003
    Messages:
    128
    Likes Received:
    0
    Theres more going on than just this, but I have a feeling that the Jump functions set the player's velocity, thus overriding anything you've told it to do.
     
  3. mccann

    mccann New Member

    Joined:
    May 24, 2004
    Messages:
    18
    Likes Received:
    0
    Thanks for the response. The code tried above has been done with different lines commented out... I was trying to show all the 'things' that I've tried (in combonations and singularly)... not necessarily exact code that I'm calling. For example, inside the NetDamage method I just tried changing the player's velocity, but it did not move my player. Any other ideas?

    I'm attaching the code... so, hopefully someone can help figure this out. :confused:
     

    Attached Files:

    Last edited: May 26, 2004
  4. Wulff

    Wulff Bola Gun fun anyone?

    Joined:
    May 25, 2004
    Messages:
    613
    Likes Received:
    0
    It'd be handier to set a kickmomentum for the primary fire, it'd also be somewhat more playerfriendly when someone is just scrolling through his/her weaponlist.
     
  5. mccann

    mccann New Member

    Joined:
    May 24, 2004
    Messages:
    18
    Likes Received:
    0
    good point. That might work too.

    What I was trying to do was bounce the player in the air after the player has fallen to the ground (with the shield gun activated) instead of just hitting the ground.
     
  6. dataangel

    dataangel New Member

    Joined:
    Apr 11, 2004
    Messages:
    184
    Likes Received:
    0
    I needed bouncing players for my mod and it took a lot of time before I found a working method. I'm not sure how to do this in a normal mutator, because it requires a new pawn (which is more characteristic of a mod, since replacing pawns will most likely break your mutator's compatibility with other mutators).

    The trick is to define a new ModifyVelocity function for your pawn. This is the absolute last thing called velocity wise and always gets the last word -- so any velocity changes made here must happen. So in Landed() you set a bool to true. Then in modifyvelocity if this bool is true you MirrorVectorByNormal(Velocity, HitNormal) and MirrorVectorByNormal(Acceleration, HitNormal). You will have to temporarily store the HitNormal too.

    But that just makes it work for hitting walls! Because a physics changed is also applied by the engine when you land, that's not enough. Apparently physics changed take an extra tick. So you have to make it wait an extra tick before applying the velocity change. Here's some example code:

    Code:
    //Bounce variables
    var vector tempVelocity; //Added in modifyvelocity()
    var vector tempAcceleration;
    var bool bMovementVectorsChanged;
    var bool tempLandedWaitATick;
    var bool justHitWall;
    var float BounceDampenFactor;
    
    function BouncePawn(vector HitNormal)
    {
        tempVelocity = MirrorVectorByNormal(Velocity, HitNormal);
        tempAcceleration = MirrorVectorByNormal(Acceleration, HitNormal);
        bMovementVectorsChanged = true; //Velocity actually updated in ModifyVelocity()
    }
    
    event Landed(vector HitNormal)
    {
        //Ugly hack to make limit number of floor bounces
        if(justHitWall && (Abs(Velocity.Z) > Abs(default.JumpZ)) && Velocity.X > 0 && Velocity.Y > 0)
        {
            BouncePawn(HitNormal);
            tempLandedWaitATick = true; //Have to wait a tick before applying due to physics change
        }
    
        justHitWall = false;
    
        Super.Landed( HitNormal );
    }
    
    simulated event ModifyVelocity(float DeltaTime, vector OldVelocity)
    {
        if(bMovementVectorsChanged)
        {
            if(tempLandedWaitATick)
            {
                SetPhysics(PHYS_Falling);
                tempLandedWaitATick = false;
            }
            else
            {
                Velocity = tempVelocity * BounceDampenFactor;
                Acceleration = tempAcceleration;
                bMovementVectorsChanged = false;
            }
        }
    }
    
    P.S. If you know something nicer than that ugly hack for making it so the player doesn't make a bunch of tiny little bounces over and over, lemme know ;)
     
    Last edited: May 30, 2004
  7. MonsOlympus

    MonsOlympus Active Member

    Joined:
    May 27, 2004
    Messages:
    2,225
    Likes Received:
    0
    This is just a stab in the dark!
    the pawns Maxfallvelocity can tell when to take damage when the pawn hits the ground. Maybe you could use this fall velocity vector for something.
    Im not a great uscripter so please excuse my stupidity. Thats if I dont make any sense.

    Maybe you could add this to the jumpheight then make the pawn jump.
    Then reset the jumpheight to default. You should be able to do this with a mutator Im not sure about this though.
     
    Last edited: May 30, 2004
  8. dataangel

    dataangel New Member

    Joined:
    Apr 11, 2004
    Messages:
    184
    Likes Received:
    0
    Well, the pawn has MaxFallRate, which I've already used. I tried some stuff like, only bounce if the fall is from greater than jumpheight, but it didn't "feel" right.
     

Share This Page