Announcement

Collapse
No announcement yet.

Sidescroller style game issue. Player rotation help!

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

    Sidescroller style game issue. Player rotation help!

    I am currently developing a side scroller style game, the main difference being the player runs around the edge of a circle, instead of just on 1 axis.
    At the moment the player runs on a correct path however I have two small issues I cannot solve (this is my first tackle at unrealscript )
    1. The player currently controls with the W and S keys to move left and right, i would like this to be done using A and D instead.
    2. When moving backwards, the player currently runs backwards however I need the character to flip and appear to run forward still. (I have tried editing the playerWalking state but had no luck.)

    Here is my code if it helps.
    Pawn Class
    Code:
    class sidescroller_pawn extends UTPawn;
    
    var float Radius;
    var float CamRadius;
    var Vector CamLocation;
    var Rotator CamRotation;
    
    var float FaceDir; // 1 or -1
    
    //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;
          }
       }
    }
    event Tick(float dt)
    {
    	local Vector center, dir;
    	local Rotator rot;
    
    	center.Z = Location.Z;
    
    	dir = Normal(Location - center);
    
    	SetLocation(dir * Radius + vect(0,0,1) * Location.Z);
    	
    	rot.Yaw = FaceDir * 16384;
    
    	SetRotation(Rotator( dir << rot ));
    
    	CamLocation = dir * CamRadius + vect(0,0,1) * Location.Z;
    	CamRotation = Rotator(-dir);
    }
    
    simulated singular event Rotator GetBaseAimRotation()
    {
    	local rotator POVRot;
    
    	POVRot = Rotation;
    
    	return POVRot;
    } 
    
    simulated function bool CalcCamera( float fDeltaTime, out vector out_CamLoc, out rotator out_CamRot, out float out_FOV )
    {
    	out_CamLoc = CamLocation;
    	out_CamLoc.Z = out_CamLoc.Z + 150;
    	out_CamRot = CamRotation;
    }
    
    DefaultProperties
    {
    	Radius=1000
    	CamRadius=1400
    	FaceDir=1
    }
    Controller Class
    Code:
    class sidescroller_controller extends UTPlayerController;
    
    state PlayerWalking
    {
    	ignores SeePlayer, HearNoise, Bump;
    
    	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();
    	}
    }
    
    defaultproperties
    {
    
    }
    Any help would be greatly appreciated

    #2
    Spent several hours today trying to achieve this but still no results just frustration doesn't anybody have a solution?

    Comment


      #3
      Bump, thinking aloud here. I think the solution is something to do with making the character flip when his POV is 0/180 degrees in relation to the camera but I have no idea how to put this into code to test. :/ does anybody have any ideas at all?

      Comment


        #4
        Look at the platformer starter kit.

        Comment


          #5
          Originally posted by cube2222 View Post
          Look at the platformer starter kit.
          I have, it is where I am getting how I think it would work from, but I cannot for the life of me implement it

          Comment


            #6
            Put this into the player controller, and if it doesnt work, remove that processmove function you made:
            Code:
            function UpdateRotation(float DeltaTime)
            {
                local Rotator DeltaRot;
            
                DeltaRot = DesiredRotation;
                DeltaRot.Pitch = PlayerInput.aLookUp;
                DeltaRot.Roll = 0;
            
                ViewShake(DeltaTime);
            
                if (Pawn != None)
                {
                    Pawn.FaceRotation(DeltaRot, DeltaTime);
                }
            }
            
            state PlayerWalking
            {
                function PlayerMove(float DeltaTime)
                {
                    local Vector X, Y, Z, NewAccel, CameraLocation;
                    local Rotator OldRotation, CameraRotation;
                    local bool bSaveJump;
            
                    if (Pawn == None)
                    {
                        GotoState('Dead');
                    }
                    else
                    {
                        PlayerCamera.GetCameraViewPoint(CameraLocation, CameraRotation);
            
                        GetAxes(CameraRotation, X, Y, Z);
            
                        NewAccel = PlayerInput.aStrafe * Y;
                        NewAccel.Z = 0;
                        NewAccel = Pawn.AccelRate * Normal(NewAccel);
            
            
                        DesiredRotation = Rotator(NewAccel);
            
            
                        OldRotation = Rotation;
                        UpdateRotation(DeltaTime);
            
            
                        Pawn.ShouldCrouch(bool(bDuck));
            
            
                        if (bPressedJump && Pawn.CannotJumpNow())
                        {
                            bSaveJump = true;
                            bPressedJump = false;
                        }
                        else
                        {
                            bSaveJump = false;
                        }
            
                        if (Role < ROLE_Authority)
                        {
                            ReplicateMove(DeltaTime, NewAccel, DCLICK_None, OldRotation - Rotation);
                        }
                        else
                        {
                            ProcessMove(DeltaTime, NewAccel, DCLICK_None, OldRotation - Rotation);
                        }
            
                        bPressedJump = bSaveJump;
                    }
                }
            }
            And this into your pawn class:
            Code:
            simulated function FaceRotation(Rotator NewRotation, float DeltaTime)
            {
                local Rotator FacingRotation;
            
                if (NewRotation.Yaw != 0)
                {
                    DesiredYaw = NewRotation.Yaw;
                }
            
                if (CurrentYaw != DesiredYaw)
                {
                    CurrentYaw = Lerp(CurrentYaw, DesiredYaw, TurnRate * DeltaTime);
                }
            
                if (AimNode != None)
                {
                    CurrentPitch = Clamp(CurrentPitch + NewRotation.Pitch, ViewPitchMin, ViewPitchMax);
            
                    if (CurrentPitch > 0.f)
                    {
                        AimNode.Aim.Y = float(CurrentPitch) / ViewPitchMax;
                    }
                    else if (CurrentPitch < 0.f)
                    {
                        AimNode.Aim.Y = float(CurrentPitch) / ViewPitchMin;
                        
                        if (AimNode.Aim.Y > 0.f)
                        {
                            AimNode.Aim.Y *= -1.f;
                        }
                    }
                    else
                    {
                        AimNode.Aim.Y = 0.f;
                    }
                }
            
                FacingRotation.Pitch = 0;
                FacingRotation.Yaw = CurrentYaw;
                FacingRotation.Roll = 0;
            
                SetRotation(FacingRotation);
            }
            It's all from teh platformer starter kit.

            Comment


              #7
              Thankyou for the response
              I have put this code into my classes however the player still does not move correctly.
              Now the players "movement" is limited to the A & D buttons as required however the character only runs on the spot, towards and away from the camera.
              Here is a video of what is happening

              Any more ideas, is it something to do with the movement axis?
              EDIT: I can provide the new code for the classes in full if needed
              EDIT2: The movement issue is to do with the PlayerMove function, specifically, NewAccel. As the player moving in a circle it needs to relate to more than just the Y or X axis, rather both.
              Code:
              NewAccel = PlayerInput.aStrafe * Y;
              Having it multiply by Y means it moves on the spot, where as X lets the character move either 90 degrees left or right.
              How do I relate this to both the X and Y equally. Simply multiplying them together does not work

              Comment


                #8
                Could somebody else please give this a go in UDK please. All my attempts are proving useless.

                Comment


                  #9
                  Wait, you want the Player to move on a circle, not just the Y(or X) axis?

                  Comment


                    #10
                    Originally posted by cube2222 View Post
                    Wait, you want the Player to move on a circle, not just the Y(or X) axis?
                    yes, sorry I thought I had explained that, must not have :/ so far I have the character moving in the circle using the strafe buttons, but the player itself still faces the camera (not left or right). The issue I cannot solve is making the character face left when moving left, and right when moving right.

                    Comment


                      #11
                      You can try to set the rotation in teh face rotation function, to the normalized velocity vector, something like that:
                      return Rotator(Velocity);

                      Comment


                        #12
                        Originally posted by cube2222 View Post
                        You can try to set the rotation in teh face rotation function, to the normalized velocity vector, something like that:
                        return Rotator(Velocity);
                        Tbh i don't think my FaceRotation function does anything at the moment, i have removed it from the code and the game still functions exactly the same.
                        However I think I have found out where the Rotation/direction are set.
                        Code:
                        event Tick(float dt)
                        {
                        	local Vector center, dir;
                        	local Rotator rot;
                        
                        	center.Z = Location.Z;
                        
                        	dir = Normal(Location - center);
                        
                        	SetLocation(dir * Radius + vect(0,0,1) * Location.Z);
                        	
                        	rot.Yaw = FaceDir *16384;
                        	SetRotation(Rotator(dir << rot ));
                        
                        
                        	CamLocation = dir * CamRadius + vect(0,0,1) * Location.Z;
                        	CamRotation = Rotator(-dir);
                        }
                        Setting rot.Yaw to multiply bu negative 90 degrees results in the player facing the opposite direction (however the controls are then inverted due to controlling in relation to the player not the camera)
                        Below it is where the rotation is set. So should i be trying to relate this set rotation to the velocity somehow?

                        Comment


                          #13
                          I have finally solved this problem thank heavens!
                          Thank you everybody for your help

                          Comment


                            #14
                            I have the same exact problem (with the character not rotating) but the thing is it works when i play it in editor on PC or when i use the emulator. It's not working ONLY when i run it on my device. The character walks, jumps, fires but instead of turning around it walks backwards and that only on iOS. On PC it works like a charm. Does anyone have any idea? For some reason I think it's ignoring the whole rotation code in my PlayerController class but I don't know why.

                            Comment

                            Working...
                            X