Announcement

Collapse
No announcement yet.

8-way movement + Isometric camera for side scroller

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

    8-way movement + Isometric camera for side scroller



    Here's the code for a character that moves in 8 ways, facing the direction you press, and also the isometric camera (Which is copied from UDN docs)
    Sorry if this has been covered somewhere else, haven't been on here in a while.

    PawnClass
    Code:
    class Mod2Pawn extends UTPawn;
    
    var float CamOffsetDistance; //distance to offset the camera from the player
    var int IsoCamAngle; //pitch angle of the camera
    
    //override to make player mesh visible by default
    simulated event BecomeViewTarget( PlayerController PC )
    {
       local UTPlayerController UTPC;
    
       Super.BecomeViewTarget(PC);
    
       if (LocalPlayer(PC.Player) != None)
       {
          UTPC = UTPlayerController(PC);
          if (UTPC != None)
          {
             //set player controller to behind view and make mesh visible
             UTPC.SetBehindView(true);
             SetMeshVisibility(UTPC.bBehindView); 
             UTPC.bNoCrosshair = true;
          }
       }
    }
    
    simulated function bool CalcCamera( float fDeltaTime, out vector out_CamLoc, out rotator out_CamRot, out float out_FOV )
    {
       out_CamLoc = Location;
       out_CamLoc.X -= Cos(IsoCamAngle * UnrRotToRad) * CamOffsetDistance;
       out_CamLoc.Z += Sin(IsoCamAngle * UnrRotToRad) * CamOffsetDistance;
    
       out_CamRot.Pitch = -1 * IsoCamAngle;   
       out_CamRot.Yaw = 0;
       out_CamRot.Roll = 0;
    
       return true;
    }
    
    simulated singular event Rotator GetBaseAimRotation()
    {
       local rotator   POVRot, tempRot;
    
       tempRot = Rotation;
       tempRot.Pitch = 0;
       SetRotation(tempRot);
       POVRot = Rotation;
       POVRot.Pitch = 0;
    
       return POVRot;
    }   
    
    defaultproperties
    {
       IsoCamAngle=6420 //35.264 degrees
       CamOffsetDistance=384.0
    }
    Player Controller Class
    Code:
    class Mod2PlayerController extends UTPlayerController;
    
    
    state PlayerWalking
    {
    ignores SeePlayer, HearNoise, Bump;
    
    event NotifyPhysicsVolumeChange( PhysicsVolume NewVolume )
    {
    if ( NewVolume.bWaterVolume && Pawn.bCollideWorld )
    {
    GotoState(Pawn.WaterMovementState);
    }
    }
    
    function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
    {
    if( Pawn == None )
    {
    return;
    }
    
    if (Role == ROLE_Authority)
    {
    // Update ViewPitch for remote clients
    Pawn.SetRemoteViewPitch( Rotation.Pitch );
    }
    
    Pawn.Acceleration = NewAccel;
    
    CheckJumpOrDuck();
    }
    
    function PlayerMove( float DeltaTime )
    {
    local vector	 X,Y,Z, NewAccel;
    local eDoubleClickDir	DoubleClickMove;
    local bool	 bSaveJump;
    local Rotator DeltaRot, ViewRotation, OldRot, NewRot;;
    
    
    if( Pawn == None )
    {
    GotoState('Dead');
    }
    else
    {
    GetAxes(Rotation,X,Y,Z);
    
    //update viewrotation
    
    ViewRotation = Rotation;
    
    // Calculate Delta to be applied on ViewRotation
    
    ProcessViewRotation( DeltaTime, ViewRotation, DeltaRot );
    SetRotation(ViewRotation);
    
    // Update acceleration.
    NewAccel = PlayerInput.aForward*X + PlayerInput.aStrafe*Y;
    NewAccel.Z	= 0;
    
    
    
    // pawn face newaccel direction // 
    
    OldRot = Pawn.Rotation;
    
    if( Pawn != None )
    
    { if( NewAccel.X > 0.0 || NewAccel.X < 0.0 || NewAccel.Y > 0.0 || NewAccel.Y < 0.0 )
    
    NewRot = Rotator(NewAccel);
    else
    NewRot = Pawn.Rotation;	
    
    }
    Pawn.FaceRotation(RInterpTo(OldRot,NewRot,Deltatime,90000,true),Deltatime);
    
    
    
    NewAccel = Pawn.AccelRate * Normal(NewAccel);
    
    DoubleClickMove = PlayerInput.CheckForDoubleClickMove( DeltaTime/WorldInfo.TimeDilation );
    
    
    
    
    bDoubleJump=false;
    
    if( bPressedJump && Pawn.CannotJumpNow() )
    {
    bSaveJump = true;
    bPressedJump = false;
    }
    else
    {
    bSaveJump = false;
    }
    
    ProcessMove(DeltaTime, NewAccel, DoubleClickMove,Rotation);
    
    
    bPressedJump = bSaveJump;
    }
    
    
    
    }	
    
    event BeginState(Name PreviousStateName)
    {
    DoubleClickDir = DCLICK_None;
    bPressedJump = false;
    GroundPitch = 0;
    if ( Pawn != None )
    {
    Pawn.ShouldCrouch(false);
    if (Pawn.Physics != PHYS_Falling && Pawn.Physics != PHYS_RigidBody) // FIXME HACK!!!
    Pawn.SetPhysics(PHYS_Walking);
    }
    }
    
    event EndState(Name NextStateName)
    {
    GroundPitch = 0;
    if ( Pawn != None )
    {
    Pawn.SetRemoteViewPitch( 0 );
    if ( bDuck == 0 )
    {
    Pawn.ShouldCrouch(false);
    }
    }
    }
    
    Begin:
    }
    
    DefaultProperties
    {
    
    
    }
    Gameinfo class
    Code:
    class Mod2Game extends UTGame;
    
    defaultproperties
    {
    
    bRestartLevel=False
    
    //bUseClassicHUD=true
       DefaultPawnClass=class'MyMod2.Mod2Pawn'
       PlayerControllerClass=class'MyMod2.Mod2PlayerController'
       //MapPrefixes[0]="UDN"
       bDelayedStart = false
       
    }
    Note to scripters: You may puke at the layout, but I am no programmer, so please go easy =]

    TUTORIAL

    Ok, so grab the MyMod2 zip from here: https://drive.google.com/file/d/0B2r...it?usp=sharing

    Unzip and place MyMod2 in UDK>Development > Src

    Then head over to UDK > UDKGame > Config
    Double click DefaultEngine.ini find where it says +EditPackages=UTGameContent and underneath that type +EditPackages=MyMod2

    Boot up UnrealFront end, build scripts, and then fire up the editor

    In the editor make sure you select World properties > Game Type and select MyMod from there

    Play the game and the new camera and movement should be in place
    Attached Files

    #2
    Looks awesome might give this a whirl for my arcade game

    Comment


      #3
      This is an epoch-making script!

      However, an error is displayed.

      "Bad or missing expression in Call to'RIterpTo', parameter 3"
      In Player Controller Class

      Why is it?

      Comment


        #4
        Originally posted by hdffg View Post
        This is an epoch-making script!

        However, an error is displayed.

        "Bad or missing expression in Call to'RIterpTo', parameter 3"
        In Player Controller Class

        Why is it?
        That is an odd one, not too sure,
        Which version of UDK are you using?
        I will try the code out tomorrow and let you know if I find any errors on a new install

        Comment


          #5
          I see zombie killer already from that ! could be awsome , or fantasy RPG kinda like baldurs gate : P

          Comment


            #6
            Originally posted by Dodge View Post
            That is an odd one, not too sure,
            Which version of UDK are you using?
            I will try the code out tomorrow and let you know if I find any errors on a new install

            Thank you for reply.

            UDK Ver is 2013-07.
            This is a detailed log.



            [0007.24] Analyzing...
            [0010.15] C:\UDK\UDK-2013-07\Development\Src\UTGame\Classes\Mod2PlayerContro ller.uc(79) : Error, Bad or missing expression in Call to 'RInterpTo', parameter 3
            [0010.97] Compile aborted due to errors.
            [0011.01]
            [0011.01] Warning/Error Summary
            [0011.01] ---------------------
            [0011.01] C:\UDK\UDK-2013-07\Development\Src\UTGame\Classes\Mod2PlayerContro ller.uc(79) : Error, Bad or missing expression in Call to 'RInterpTo', parameter 3
            [0011.01]
            [0011.01] Failure - 1 error(s), 0 warning(s)
            [0011.01]


            Three scripts exhibited this time are put on  Developmet-Src-MyFolder-Classes-[in a put 3 scripts]

            I thought.

            Is it necessary to write in the command (for example, Other .uc) for recognizing three スクリプト を in "My-Folder" in UDK?

            I am sorry for not being good at English.

            Thank you.

            Comment


              #7
              thanks for the tutorial, really good !!!!

              Comment


                #8
                Originally posted by hdffg View Post
                This is an epoch-making script!

                However, an error is displayed.

                "Bad or missing expression in Call to'RIterpTo', parameter 3"
                In Player Controller Class

                Why is it?
                Found it out!
                Turns out if you copy the code I put up, when pasted into a txt file it is putting a big space on the word DeltaTime on the said line.
                So just get rid of the space and you are good to go!

                Comment


                  #9
                  wonder...


                  Thank you Dodge.

                  Comment


                    #10
                    For us laymans, could you tell us how to implement the scripts? I've created a PawnClass uc file and edited copies of the PlayerController and Gameinfo scripts though it's error heavy.

                    Comment


                      #11
                      Hi Nosajxe,

                      Course I can, although you will have to give me till tomorrow, and i'll do a little write up of implementing it =]
                      What errors are you getting?

                      Cheers

                      Note: Just to check have you added the package in? (Check image)
                      Attached Files

                      Comment


                        #12
                        How do I use this script now ?

                        Comment


                          #13
                          I will try to get something tutorial-ish uploaded in the next few days, bogged down at work so not much free time.
                          Have a nosey on the forums for something like 'Creating your first mod' or 'how to add custom script', in the mean time =]

                          Comment


                            #14
                            Originally posted by Clarity View Post
                            How do I use this script now ?
                            Tutorial added to first post

                            Comment


                              #15
                              Great tutorial and fluid motion with the script not to mention NO loss of 3rd person view and ability to add weapons and extras to pawn.. only thing and it might just be me.. does your wasd forward, backward etc seem reversed.. forward always goes down the map S goes up the map.. also was the mouse supposed to have any fucntion? or for now will it just be extra for later use for menu and selection process kinda loke tera press alt to initiate

                              Comment

                              Working...
                              X