Announcement

Collapse
No announcement yet.

Player Camera and Pawn rotation

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

    Player Camera and Pawn rotation

    READ NEXT POST, UPDATED CODE

    Hey all, got myself in a pickle with a camera problem, and I am terrible at maths.

    I found and implemented this camera and tweaked it to my needs as far as I could.

    Now, however, I need the pawn to rotate smoothly on WASD controls the same way it does with a Joystick, while also rotating the pawn separately from the camera.

    So far I've gotten it moving interdependently from the camera while moving forward....however if I try to move in any other direction....

    This is what happens.

    Hilarious, but not useful sadly.

    Here is the relevant code from my PlayerController class. It only differs from the original in a few places, look for comments.

    Code:
    //==============================//
    //          BEGIN CAMERA MOD                 //
    //==============================//
    
    exec function ZoomIn() 
    {
    	if (GamePlayerCamera(PlayerCamera).CameraStyle == 'FreeCam_Default') 
    	{
    		if (PlayerCamera.FreeCamDistance > 32)
    		{
    			PlayerCamera.FreeCamDistance -= (PlayerCamera.FreeCamDistance/8); 
    		}
    	}
    }
    
    exec function ZoomOut() 
    {
    	if (GamePlayerCamera(PlayerCamera).CameraStyle == 'FreeCam_Default') 
    	{
    		if (PlayerCamera.FreeCamDistance < 512)
    		{
    			PlayerCamera.FreeCamDistance += (PlayerCamera.FreeCamDistance/8); 
    		}
    	}
    }
    
    function HideMesh(bool meshVisible) 
    {
    	Pawn.Mesh.SetOwnerNoSee(meshVisible);
    }
    
    exec function ToggleCam()
    {
    	if(GamePlayerCamera(PlayerCamera).CameraStyle == 'FreeCam_Default')
    	{
    		GamePlayerCamera(PlayerCamera).CameraStyle = 'FirstPerson';
    		HideMesh(true);
    	}
    	else
    	{
    		GamePlayerCamera(PlayerCamera).CameraStyle = 'FreeCam_Default';
    		HideMesh(false);
    	}
    }
    
    state PlayerWalking
    {
    	function PlayerMove( float DeltaTime )
    	{
    		local vector			X,Y,Z, NewAccel;
    		local eDoubleClickDir	DoubleClickMove;
    		local rotator			OldRotation;
    		local bool				bSaveJump;
    
    		local rotator tempRot;
    
    		tempRot.Pitch = Pawn.Rotation.Pitch;
    		tempRot.Roll = 0;
    
    		if(PlayerInput.RawJoyUp > 0.0) // FORWARD
    		{
    			tempRot.Yaw = Pawn.Rotation.Yaw + 16384* PlayerInput.RawJoyRight; // I changed Pawn.Roation.Yaw from PlayerCamera.Rotation.Yaw. Last of my tweaks.
    			Pawn.SetRotation(tempRot);
    		}
    		if(PlayerInput.RawJoyUp < 0.0) // BACKWARD
    		{
    			tempRot.Yaw = Pawn.Rotation.Yaw + 32768 - 16384* PlayerInput.RawJoyRight; //likewise
    			Pawn.SetRotation(tempRot);
    		}
    		if(PlayerInput.RawJoyUp == 0.0)
    		{
    			if(PlayerInput.RawJoyRight > 0.0) //RIGHT
    			{
    				tempRot.Yaw = Pawn.Rotation.Yaw + 16384; //you guessed it, same again
    				Pawn.SetRotation(tempRot);
    			}
    			if(PlayerInput.RawJoyRight < 0.0) //LEFT
    			{
    				tempRot.Yaw = Pawn.Rotation.Yaw - 16384; //yeah
    				Pawn.SetRotation(tempRot);
    			}
    		}
    
    
    		if( Pawn == None )
    		{
    			GotoState('Dead');
    		}
    		else
    		{
    			GetAxes(Pawn.Rotation,X,Y,Z); //This was originally PlayerCamera.Rotation,X,Y,Z but I changed it to Pawn.
    
    			// Update acceleration.
    			NewAccel = PlayerInput.aForward*X + PlayerInput.aStrafe*Y;
    			NewAccel.Z	= 0;
    			NewAccel = Pawn.AccelRate * Normal(NewAccel);
    
    			DoubleClickMove = PlayerInput.CheckForDoubleClickMove( DeltaTime/WorldInfo.TimeDilation );
    
    			// Update rotation.
    			OldRotation = Rotation;
    			UpdateRotation( DeltaTime );
    			bDoubleJump = false;
    
    			if( bPressedJump && Pawn.CannotJumpNow() )
    			{
    				bSaveJump = true;
    				bPressedJump = false;
    			}
    			else
    			{
    				bSaveJump = false;
    			}
    
    			if( Role < ROLE_Authority ) // then save this move and replicate it
    			{
    				ReplicateMove(DeltaTime, NewAccel, DoubleClickMove, OldRotation - Rotation);
    			}
    			else
    			{
    				ProcessMove(DeltaTime, NewAccel, DoubleClickMove, OldRotation - Rotation);
    			}
    			bPressedJump = bSaveJump;
    		}
    	}
    }
    
    state PlayerSwimming
    {
    	function PlayerMove(float DeltaTime)
    	{
    		local rotator tempRot;
    
    		super.PlayerMove( DeltaTime );
    
    		tempRot.Pitch = Pawn.Rotation.Pitch;
    		tempRot.Roll = 0;
    
    		if(PlayerInput.RawJoyUp > 0.0)
    		{
    			tempRot.Yaw = PlayerCamera.Rotation.Yaw + 16384* PlayerInput.RawJoyRight;
    			Pawn.SetRotation(tempRot);
    		}
    		if(PlayerInput.RawJoyUp < 0.0)
    		{
    			tempRot.Yaw = PlayerCamera.Rotation.Yaw + 32768 - 16384* PlayerInput.RawJoyRight;
    			Pawn.SetRotation(tempRot);
    		}
    		if(PlayerInput.RawJoyUp == 0.0)
    		{
    			if(PlayerInput.RawJoyRight > 0.0)
    			{
    				tempRot.Yaw = PlayerCamera.Rotation.Yaw + 16384;
    				Pawn.SetRotation(tempRot);
    			}
    			if(PlayerInput.RawJoyRight < 0.0)
    			{
    				tempRot.Yaw = PlayerCamera.Rotation.Yaw - 16384;
    				Pawn.SetRotation(tempRot);
    			}
    		}
    	}
    }
    
    state PlayerFlying
    {
    	function PlayerMove(float DeltaTime)
    	{
    		local rotator tempRot;
    
    		super.PlayerMove( DeltaTime );
    
    		tempRot.Pitch = Pawn.Rotation.Pitch;
    		tempRot.Roll = 0;
    
    		if(PlayerInput.RawJoyUp > 0.0)
    		{
    			tempRot.Yaw = PlayerCamera.Rotation.Yaw + 16384* PlayerInput.RawJoyRight;
    			Pawn.SetRotation(tempRot);
    		}
    		if(PlayerInput.RawJoyUp < 0.0)
    		{
    			tempRot.Yaw = PlayerCamera.Rotation.Yaw + 32768 - 16384* PlayerInput.RawJoyRight;
    			Pawn.SetRotation(tempRot);
    		}
    		if(PlayerInput.RawJoyUp == 0.0)
    		{
    			if(PlayerInput.RawJoyRight > 0.0)
    			{
    				tempRot.Yaw = PlayerCamera.Rotation.Yaw + 16384;
    				Pawn.SetRotation(tempRot);
    			}
    			if(PlayerInput.RawJoyRight < 0.0)
    			{
    				tempRot.Yaw = PlayerCamera.Rotation.Yaw - 16384;
    				Pawn.SetRotation(tempRot);
    			}
    		}
    	}
    }
    
    
    //==============================//
    //          End   CAMERA MOD                  //
    //==============================//
    
    ...
    
    defaultProperties
    {
        CameraClass=class'GameFramework.GamePlayerCamera'
    }

    I've asked in the original thread for help but am not gonna be holding my breath for help in a thread > a year old.

    This is the best player camera that I've found that works so well, any ideas on making it jump the last hurdle?

    #2
    Well lack of replies notwithstanding, I've done my best to fix it and have changed a lot of the code and now have a different, albeit related problem. relevant parts of code looks like this now:

    Code:
    class TDPlayerController extends UDKPlayercontroller;
    
    ...
    
    ...
    
    function UpdateRotation(float DeltaTime)
    {
        local rotator       DeltaRot, newRotation, ViewRotation;
        
        ViewRotation = Rotation;
        
        if(pawn !=none)
        {
            Pawn.SetDesiredRotation(ViewRotation);
        }
        
        DeltaRot.Yaw = PlayerInput.aTurn;
        DeltaRot.Pitch = PlayerInput.aLookUp;
        
        ProcessViewRotation(DeltaTime, ViewRotation, DeltaRot);
        SetRotation(ViewRotation);
        
        self.ViewRotationPitch = ViewRotation.Pitch;
        
        ViewShake(DeltaTime);
        
        NewRotation = ViewRotation;
        NewRotation.Roll = Rotation.Roll;
        
        if(Pawn != none && (PlayerInput.RawJoyRight != 0.0 || PlayerInput.RawJoyUp != 0.0))
            Pawn.FaceRotation(NewRotation, DeltaTime);
    }
    
    state PlayerWalking
    {
        
        function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
        {
            if(Pawn == none)
            {
                `log("No Pawn!==========================");
                return;
            }
            
            if(Role == ROLE_Authority)
            {
                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)
            {
                `log("No Pawn!==================");
                GoToState('Dead');
            }
            
            else
            {
                GetAxes(Rotation,X,Y,Z);
                
                ViewRotation = Rotation;
                
                DeltaRot.Yaw = PlayerInput.aTurn;
                DeltaRot.Pitch = PlayerInput.aLookUp;
                ProcessViewRotation(DeltaTime, ViewRotation, DeltaRot);
                SetRotation(ViewRotation);
                
                NewAccel = PlayerInput.aForward*X + PlayerInput.aStrafe*Y;
                NewAccel.Z = 0;
                
                OldRot = Pawn.Rotation;
                
                if(Pawn != none)
                {
                    if(NewAccel.X > 0.0 || NewAccel.Y > 0.0 || NewAccel.X < 0.0 || NewAccel.Y < 0.0)
                        NewRot = Rotator(NewAccel);
                    else
                        NewRot = Pawn.Rotation;
                }
                
                //here be pawn controlling, appears that NewRot isnt getting anything in its first and third values
                Pawn.FaceRotation(RInterpTo(OldRot, NewRot, DeltaTime, 90000, true), DeltaTime);
                `log("=====================All the ****:" @ OldRot @ NewRot);
                WorldInfo.Game.Broadcast(self, "=====================All the ****:" @ OldRot @ NewRot);
                
                
                NewAccel = Pawn.AccelRate * Normal(NewAccel);
                
                DoubleClickMove = PlayerInput.CheckforDoubleClickMove(DeltaTime / WorldInfo.TimeDilation);
                
                if(bPressedJump && Pawn.CannotJumpNow())
                {
                    bSaveJump = true;
                    bPressedJump = true;
                }
                
                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)
                    Pawn.SetPhysics(PHYS_Walking);
            }
        }
            
        event EndState(Name NextStateName)
        {
            GroundPitch = 0;
                
            if(Pawn != none)
            {
                Pawn.SetRemoteViewPitch(0);
                    
                if(bDuck == 0)
                {
                    Pawn.ShouldCrouch(false);
                }
            }
        }
    }
    
    ...
    
    ...
    
    defaultProperties
    {
        CameraClass=class'GameFramework.GamePlayerCamera'
    }
    so right now, the camera rotates freely and the pawns moves relative to it. However the pawn faces in its original position, regardless of movement.

    You can see here:
    Code:
                //here be pawn controlling, appears that NewRot isnt getting anything in its first and third values
                Pawn.FaceRotation(RInterpTo(OldRot, NewRot, DeltaTime, 90000, true), DeltaTime);
                `log("=====================All the ****:" @ OldRot @ NewRot);
                WorldInfo.Game.Broadcast(self, "=====================All the ****:" @ OldRot @ NewRot);
    What appears to be happening (or what I think is happening at least)



    I've already tried Rotator(Pawn.Velocity) to no avail.

    I'm kinda lost and scared at the moment. Anyone see where I've munted it?

    Comment


      #3
      Sort of solved it, but not really.

      Replaced:
      Code:
       Pawn.FaceRotation(RInterpTo(OldRot, NewRot, DeltaTime, 90000, true), DeltaTime);
      with
      Code:
      Pawn.SetRotation(RInterpTo(OldRot, NewRot, DeltaTime, 50000, true));
      and its works how I desire. still will have to tweak with the speed of the interpolation but thats **** all compared to the hole in my desk made by my head at this point.

      Comment

      Working...
      X