| Home Page | Recent Changes | Preferences

Wizzie/PawnLeggsRotation

This is the code I use for rotating the legs of the pawn in the same direction as it moves. It's somewhat experimental and is in need of a major overhaul, but it works for now.

class pPawn extends xPawn;

enum E_LEGSSTATE
{
    E_LEGSSTRAFING,
    E_LEGSFORWARD,
    E_LEGSBACKWARD
};

var name PelvisBone;
var name SpineBone;

var E_LEGSSTATE LegsAnimSet;
var E_LEGSSTATE LegsLastAnimSet;

var int LegsActuallRollAngle;
var int LegsRollAngle;
var int LegsRotationSpeed;

    ...
    ...
    ...

simulated function Tick(float DeltaTime)
{
    ...
    ...
    ...

    SetAnimationDirection( DeltaTime );
}

simulated function SetAnimationDirection( float DeltaTime )
{
    local float tY, tX;
    local rotator r1, r2;
    local vector X,Y,Z, Dir;

    if( Velocity.x != 0 || Velocity.y != 0 )
    {
        GetAxes( Rotation, X,Y,Z );
        Dir = Normal(Velocity);

        tX = X dot Dir;
        tY = Y dot Dir;

        // The rotator values for the legs requires a bit of tweeking
        if( tX < 0.1 && tX > -0.1 )  // only strafing
        {
            LegsRollAngle = 0;
            LegsAnimSet = E_LEGSSTRAFING;
        }
        else if( tX >= -0.01 ) // walking forward
        {
            if( tY > 0 )
                LegsRollAngle = 8000 * -tY;
            else
                LegsRollAngle = 12000 * -tY;

            LegsAnimSet = E_LEGSFORWARD;
        }
        else    // backwards
        {
            if( tY > 0 )
                LegsRollAngle = 12000 * tY;
            else
                LegsRollAngle = 8000 * tY;
            LegsAnimSet = E_LEGSBACKWARD;
        }

        if( LegsAnimSet !=  LegsLastAnimSet )
        {
            switch( LegsAnimSet )
            {
                case E_LEGSSTRAFING:
                    MovementAnims[2]='RunL';
                    MovementAnims[3]='RunR';
                    WalkAnims[2]='WalkL';
                    WalkAnims[3]='WalkR';
                    CrouchAnims[2]='CrouchL';
                    CrouchAnims[3]='CrouchR';
                    break;

                case E_LEGSFORWARD:
                    MovementAnims[2]='RunF';
                    MovementAnims[3]='RunF';
                    WalkAnims[2]='WalkF';
                    WalkAnims[3]='WalkF';
                    CrouchAnims[2]='CrouchF';
                    CrouchAnims[3]='CrouchF';
                    break;

                case E_LEGSBACKWARD:
                    MovementAnims[2]='RunB';
                    MovementAnims[3]='RunB';
                    WalkAnims[2]='WalkB';
                    WalkAnims[3]='WalkB';
                    CrouchAnims[2]='CrouchB';
                    CrouchAnims[3]='CrouchB';
                    break;
            }
            LegsLastAnimSet = LegsAnimSet;
        }
    }
    else    // no movement, turn legs back to initial position over time
    {
        LegsRollAngle = 0;
    }

    if( LegsActuallRollAngle != LegsRollAngle )
    {
        if( LegsRollAngle > LegsActuallRollAngle  )
        {
            LegsActuallRollAngle += (LegsRotationSpeed*DeltaTime);
            if( LegsActuallRollAngle >= LegsRollAngle )
                LegsActuallRollAngle = LegsRollAngle;
        }
        else
        {
            LegsActuallRollAngle -= (LegsRotationSpeed*DeltaTime);
            if( LegsActuallRollAngle <= LegsRollAngle )
                LegsActuallRollAngle = LegsRollAngle;
        }


        r1.roll = LegsActuallRollAngle;
        r1.yaw = 0;
        r1.pitch = 0;
        r2.roll = -r1.roll;
        r2.yaw = 0;
        r2.pitch = 0;

        SetBoneRotation( PelvisBone, r2 );  // this will rotate the entire pawn
        SetBoneRotation( SpineBone, r1 );   // rotate the upper body back to original position
    }
}

defaultproperties
{
    ...
    ...
    ...

    PelvisBone          = "Bip01 Pelvis"
    SpineBone           = "Bip01 Spine"
    LegsRotationSpeed   = 80000
}

GRAF1K: Um... unless you're rotating pantyhose, it's legs, not leggs. :D

wizzie: Sorry for spelling errors, english isn't my first language. Corrected the leggs thingy on the page but can't rename the page itself. Moved comments down below aswell. Feel free to correct any other errors or improvements :)

GRAF1K: It really doesn't matter... It's your own page. Just thought it was funny. :-)

Category Custom Class

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Image Uploads

Random Page

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

Mapping Topics

Mapping Lessons

UnrealEd Interface

Questions&Answers

Scripting Topics

Scripting Lessons

Making Mods

Class Tree

Questions&Answers

Modeling Topics

Questions&Answers

Log In