Announcement

Collapse
No announcement yet.

Need Help with the SetPawnRotation()

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Need Help with the SetPawnRotation()

    I've been working on a side-scroller mod for UT2k4 I've made it so the character can turn around and face his acceleraton with this code

    state PlayerWalking
    {
    function PlayerMove( float DeltaTime )
    {

    local bool wForward;
    local rotator bRot, fRot;

    fRot = (rotator(vect(0,32768,0)));
    bRot = (rotator(vect(0,-32768,0)));

    Super.PlayerMove( DeltaTime );

    if (pawn!= none)
    {
    if (aforward > 0)
    {
    Pawn.SetRotation(fRot);
    Pawn.Acceleration = Pawn.Acceleration * 1;
    wForward = true;
    }
    if (aforward < 0)
    {
    Pawn.SetRotation(bRot);
    Pawn.Acceleration = Pawn.Acceleration * -1;
    wForward = false;
    }
    if (aforward == 0)
    {
    if (wForward == true)
    {
    Pawn.SetRotation(fRot);
    }
    else
    {
    Pawn.SetRotation(bRot);
    }
    }
    }
    }
    }

    however after you let go of the move key the character flips back around. Does anyone have any ideas on what is causing this?

    #2
    Your wForward property is local. That makes it set false at begining of each function execution - all you've done with it in previous call is simply reseted to false.

    Code:
    [...]
    
        if (aforward == 0)
        {
          // When we're here wForward is ALWAYS false
    
          if (wForward == true)
             Pawn.SetRotation(fRot);     //log("This should never happen :P");
    
    
             else
             Pawn.SetRotation(bRot);  // We're always ending up here
    
        }
    
    [...]
    To fix it simply put wForward into variables at begining of your class. You should put fRot and bRot there too and declare them in deault properties to initialize them once only. This all should help.

    Comment

    Working...
    X