Announcement

Collapse
No announcement yet.

3rd person action camera

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

    3rd person action camera

    Here's a video of it in action on YouTube.
    New video, showing the fixed bug.

    ***Description***

    This is a way of controlling the pawn and the built in freecam (extending from UDK classes) so that the pawn moves relative to the camera's rotation, rather than rotating the pawn with the camera, so it shouldn't be too hard to use it with your own custom camera and pawn, or to just add to your own player controller, depending on how complex your setup is.

    It's also got the option to toggle the default first person camera by clicking the mouse wheel. In fact when you start playing it starts you in first person. It also has basic zoom while in 3rd person, by scrolling up and down with the mouse wheel.

    The zoom and perspective toggle if using an Xbox 360 controller are up and down on the dpad and pressing the right thumbstick, respectively.

    One rather interesting feature is when you are in first person, and zoom in and out, the fov decreases and increases (like a scope zoom). This change in fov affects the 3rd person camera as well, so that when you toggle back, you can get "bug eye" or "top of a mountain" type 3rd person camera styles.

    The pawn rotates to face the direction of player input.

    Note that because these files are extending from UDK classes, not UT classes, the weapons, vehicles, items, and everything else UT related will no longer function as expected, and probably not even do anything. This is not a bug, it is intended. The Pawn included just LOOKS like the UT guy, just so you have SOMETHING to look at, to know it's working as intended. Once you got the hang of things, your next step might be to make your own pawn. You're gonna wanna make one eventually.

    A huge thanks to VolitionGames- your thread helped me out a lot (and thanks to everyone who posted something helpful in that thread). And thanks for your patience Blade[UG]. I know I ask a lot of stupid questions.
    Other than that, I used the documentation Camera Technical Guide (the section "Example Side-Scrolling Camera" oddly enough) and PlayerController.uc


    Bugs:

    Fixed. >When using a controller instead of wasd, and rolling the left thumbstick around, the pawn rotates smoothly at all angles except directly left and right, at which points it "snaps" in place. The higher you set your deadzone, the more apparent this becomes.< Fixed. Was a stupid math mistake.

    Zooming with an XBox 360 controller is rather sluggish, as you have to keep pressing the button. I'm gonna try to change that so you just have to press and hold it. I gotta learn how first though, lol.

    Turning only looks like it does in the video if you use a controller. If you are using keyboard and mouse, turns will be abrupt. I think there's something that can limit how fast your character can turn... I'll have to look into that.

    Also, this isn't really a bug, but if you use the fly command while in third person, then use the walk command while still in third person, since the walk command puts you in first person, but you were in third person, the player mesh is visible while in first person (look down). Since, when changing perspective, the mesh visibility is set based on what perspective you are in (not just toggled back and forth) this "bug" is cleared the next time you change perspective.

    #2
    ***HOW TO***
    This is a 4 step process that sounds more complicated than it is. If you already have experience in Unreal Script, scroll down to step 3.
    If you don't, and would like an explanation of what these steps do, the official beginners guide is on this page. Pay close attention to the section "Configuring, Compiling and Testing".

    I'm using the December 2010 UDK Beta. You can download it from here.

    1. First, in the folder UDK\UDK-2010-12\UDKGame\Config open the file DefaultEngine.ini and under the section headed by:

    Code:
    [UnrealEd.EditorEngine]
    add
    Code:
    +EditPackages=MyMod
    2. Then, in the same folder, but in the file DefaultGame.ini and under the section headed by:
    Code:
    [Engine.GameInfo]
    change
    Code:
    DefaultGame=UTGame.UTDeathmatch
    to
    Code:
    DefaultGame=MyMod.MyGameInfo
    then change
    Code:
    DefaultServerGame=UTGame.UTDeathmatch
    to
    Code:
    DefaultServerGame=MyMod.MyGameInfo
    and finally change
    Code:
    PlayerControllerClassName=UTGame.UTPlayerController
    to
    Code:
    PlayerControllerClassName=MyMod.MyPlayerController
    3. Next, to add the bindings, open DefaultInput.ini in the same folder and:


    In the section headed by

    Code:
    ;-----------------------------------------------------------------------------------------
    ; Game Keyboard/Mouse Bindings
    ;-----------------------------------------------------------------------------------------
    add to the bottom of the list that's already there:

    Code:
    .Bindings=(Name="MiddleMouseButton",Command="ToggleCam") 
    .Bindings=(Name="MouseScrollUp",Command="ZoomIn")
    .Bindings=(Name="MouseScrollDown",Command="ZoomOut")
    And in the section headed by:

    Code:
    ;-----------------------------------------------------------------------------------------
    ; Game Controller Bindings
    ;-----------------------------------------------------------------------------------------
    add to the bottom of the list that's already there:

    Code:
    .Bindings=(Name="XboxTypeS_RightThumbstick",Command="ToggleCam")
    .Bindings=(Name="XboxTypeS_DPad_Up",Command="ZoomIn")
    .Bindings=(Name="XboxTypeS_DPad_Down",Command="ZoomOut")
    4. Finally, add the following files to UDK\UDK-2010-12\Development\Src\MyMod\Classes

    Use notepad if you don't have an integrated development environment program. Don't use Word or anything like that because those programs don't save the files correctly. Make sure to save them as .uc files, not .txt files. Change the "Save as type:" drop box from "Text Documents (*.txt)" to "All Files (*.*)" before you hit save, or it will save it as *.uc.txt

    Once you're done, start the editor from the editor shortcut in the start menu, and it will tell you the scripts are outdated, and it will ask you if you want to rebuild now. Click yes, and an MSDos window will pop up and do a bunch of stuff, then it should say Success - 0 error(s), 0 warning(s) in green. Close that window, and start the editor from the shortcut again. Then open one of the levels that come included with the UDK (I used VCTF-Necropolis.udk in the video), and click the play in editor button (green > arrow) to run around and check it out for yourself.

    MyGameInfo.uc
    This is the first file, of 3.
    Code:
    class MyGameInfo extends UDKGame;
    
    DefaultProperties
    {
    	DefaultPawnClass = class'MyMod.MyPawn'
    	PlayerControllerClass = class'MyMod.MyPlayerController'
    	bDelayedStart = false
    	bRestartLevel = false
    }


    MyPlayerController.uc
    This is the second file.
    (This is where all the magic is)
    Code:
    class MyPlayerController extends UDKPlayerController;
    
    exec function ZoomIn() 
    {
    	if (GamePlayerCamera(PlayerCamera).CameraStyle == 'FreeCam_Default') 
    	{
    		if (PlayerCamera.FreeCamDistance > 32)
    		{
    			PlayerCamera.FreeCamDistance -= (PlayerCamera.FreeCamDistance/8); 
    		}
    	}
    	else
    	{
    		if (PlayerCamera.DefaultFOV > 30)
    		{
    			PlayerCamera.DefaultFOV -= (PlayerCamera.DefaultFOV/8);
    		}
    	}
    }
    
    exec function ZoomOut() 
    {
    	if (GamePlayerCamera(PlayerCamera).CameraStyle == 'FreeCam_Default') 
    	{
    		if (PlayerCamera.FreeCamDistance < 512)
    		{
    			PlayerCamera.FreeCamDistance += (PlayerCamera.FreeCamDistance/8); 
    		}
    	}
    	else
    	{
    		if (PlayerCamera.DefaultFOV < 120)
    		{
    			PlayerCamera.DefaultFOV += (PlayerCamera.DefaultFOV/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)
    		{
    			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);
    			}
    		}
    
    
    		if( Pawn == None )
    		{
    			GotoState('Dead');
    		}
    		else
    		{
    			GetAxes(PlayerCamera.Rotation,X,Y,Z); //By default this is Pawn instead of PlayerCamera
    
    			// 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);
    			}
    		}
    	}
    }
    
    defaultProperties
    {
    	CameraClass = class 'GameFramework.GamePlayerCamera'
    }
    Note that I'm using the camera class GamePlayerCamera, and not a custom camera class.

    MyPawn.uc
    And this is the third file.
    Nothing special, just something to look at to know it's working as intended. (the default UT character's mesh) Use your own custom pawn, if you have one.
    Code:
    class MyPawn extends UDKPawn;
    
    defaultproperties
    {
    		Components.Remove(Sprite)
    	//Setting up the light environment
    	Begin Object Class=DynamicLightEnvironmentComponent Name=MyLightEnvironment
    		ModShadowFadeoutTime=0.25
    		MinTimeBetweenFullUpdates=0.2
    		AmbientGlow=(R=.01,G=.01,B=.01,A=1)
    		AmbientShadowColor=(R=0.15,G=0.15,B=0.15)
    		bSynthesizeSHLight=TRUE
    	End Object
    	Components.Add(MyLightEnvironment)
    	
    	//Setting up the mesh and animset components
    	Begin Object Class=SkeletalMeshComponent Name=InitialSkeletalMesh
    		CastShadow=true
    		bCastDynamicShadow=true
    		bOwnerNoSee=true
    		LightEnvironment=MyLightEnvironment;
    		BlockRigidBody=true;
    		CollideActors=true;
    		BlockZeroExtent=true;
    		//What to change if you'd like to use your own meshes and animations
    		PhysicsAsset=PhysicsAsset'CH_AnimCorrupt.Mesh.SK_CH_Corrupt_Male_Physics'
    		AnimSets(0)=AnimSet'CH_AnimHuman.Anims.K_AnimHuman_AimOffset'
    		AnimSets(1)=AnimSet'CH_AnimHuman.Anims.K_AnimHuman_BaseMale'
    		AnimTreeTemplate=AnimTree'CH_AnimHuman_Tree.AT_CH_Human'
    		SkeletalMesh=SkeletalMesh'CH_LIAM_Cathode.Mesh.SK_CH_LIAM_Cathode'
    	End Object
    	
    	//Setting up a proper collision cylinder
    	Mesh=InitialSkeletalMesh;
    	Components.Add(InitialSkeletalMesh); 
    	CollisionType=COLLIDE_BlockAll
    	Begin Object Name=CollisionCylinder
    	CollisionRadius=+0023.000000
    	CollisionHeight=+0050.000000
    	End Object
    	CylinderComponent=CollisionCylinder
    
    	Buoyancy=+000.99000000
    }

    Comment


      #3
      Video doesn't work.

      -Mr. Illusive

      Comment


        #4
        I'm still uploading it. Check back in an hour, it should be done by then.

        Comment


          #5
          Ok, it's uploaded now.

          Comment


            #6
            very nice

            Comment


              #7
              Thanks for this. I have a small problem though. I can toggle the cam to third person and spin the camera around, but for some reason if I use my scroll wheel it wont zoom in or out at all.

              Comment


                #8
                If you're using a custom camera, be sure to replace 'FreeCam_Default' and PlayerCamera.FreeCamDistance with what your custom camera uses. Also, make sure you add the bindings for ZoomIn and ZoomOut (I'm not using the default exec functions for changing weapons, so that I can map it the way I want to both the keyboard/mouse setup, and the XBox 360 controller setup).

                Comment


                  #9
                  doing all you said, makes me unable to use a weapon. no weapon showing and no HUD...

                  I guess we have to add the code separately for those...
                  PS: how can you make the third person view to be default?

                  Comment


                    #10
                    Add this to the pawn class:

                    Code:
                    simulated function name GetDefaultCameraMode(PlayerController RequestedBy)
                    {
                    	return 'FreeCam_Default';
                    }
                    and make sure to set
                    Code:
                    bOwnerNoSee=false
                    in default properties.

                    And yes, whenever you extend from UDK classes, everything UT is not included. The only reason the pawn looks like the UT character is because that code was added to the custom pawn class, just to have something to look at. You would indeed have to do the same thing for anything else UT you wanted included as well.
                    You could also create your own custom classes for things similar to things in UT, without having to copy UT code. Looking through the UT code isn't a bad idea, though, as it's a good way to understand how you could go about setting up your own custom class.

                    You also may be able to modify this code to work when extending from UT classes. I'm the wrong guy to ask about that, though.

                    Comment


                      #11
                      Does this only work with Xbox controller or can the zoom in and out work with mouse, Because when I run the game i cannot see anything :S

                      Any help would be appreciated.

                      Thanks !

                      Comment


                        #12
                        These are the bindings that make it work with the mouse scrollwheel. You press the scrollwheel down to toggle between first and third person.
                        Code:
                        .Bindings=(Name="MiddleMouseButton",Command="ToggleCam") 
                        .Bindings=(Name="MouseScrollUp",Command="ZoomIn")
                        .Bindings=(Name="MouseScrollDown",Command="ZoomOut")
                        What do you mean by you can't see anything?

                        Comment


                          #13
                          When I hit the run, i see the game in fps view but without weapon etc, kinda like fly mode or something.

                          Dameeda

                          Comment


                            #14
                            You made my Day!
                            That code was help me a lot ~
                            I'm trying to do something on your code , allow my paw on turning will rotation.
                            (make turning like linear)
                            like my old game ---->http://www.youtube.com/watch?v=a8cpAyRQ4xU&hd=1#t=59s



                            another question...
                            .Bindings=(Name="MiddleMouseButton",Command="Toggl eCam") --->it work!
                            .Bindings=(Name="MouseScrollUp",Command="ZoomIn")------------>Invalid
                            .Bindings=(Name="MouseScrollDown",Command="ZoomOut ")-------->Invalid

                            thank again~

                            Comment


                              #15
                              Hi.. excellent tutorial ...

                              I want to add a custom pawn... like if I put my mesh, animation, texture in a package... what changes would I gave to make in the mypawn.uc so that the game know where to load the mesh from...??

                              Edit:

                              Hurray the custom character work... well atleast in the developer window... check in my videos below that in the developer is looks and works fine... but once cooked (no errors or warning tho) and played... no custom character nor camera... and if I load the level through command... I float in the level... links to my videos below

                              http://www.youtube.com/watch?v=vLEoNgJSDuM
                              http://www.youtube.com/watch?v=RCqMiyyTgT4

                              edit 2: this happens only after i changed it to cutom character... without it runs fine

                              Comment

                              Working...
                              X