Announcement

Collapse
No announcement yet.

UDK action game - 3rd person camera code

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

    #76
    For that code, can you show the "Lerp Function". Its used in the code snipet you gave so I would need to know whats all in it/why its being called, by viewing that function as well. I am also very new to this, so I'm just doing the best I can to help.

    Comment


      #77
      Good cam but one problem. Even through I have change default skeletal mesh and all the other things I still see the default robot character. Help please.

      Comment


        #78
        Originally posted by GentlemenGraphics View Post
        Good cam but one problem. Even through I have change default skeletal mesh and all the other things I still see the default robot character. Help please.
        Try to add the following code to mine, if thats the code your using.


        Inside the function simulated event BecomeViewTarget( PlayerController PC ). Inside the pawn class comment out the following line. It should hide the defualt mesh and let yours be visible I believe.

        PHP Code:
        SetMeshVisibility(UTPC.bBehindView); 
        Place this into the default properties. You might not need all of these, so try erasing one at a time if your getting errors because of the line, because I'm not sure if any of these are needed. I myself don't have a custom character that I can try out so hard for me to help with that.

        PHP Code:
            //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
        =false
                LightEnvironment
        =MyLightEnvironment;
                
        BlockRigidBody=true;
                
        CollideActors=true;
                
        BlockZeroExtent=true;
                
        //What to change if you'd like to use your own meshes and animations
                
        PhysicsAsset=PhysicsAsset'ioflow_rpg_characters.sarah_Physics'
                
        AnimSets(0)=AnimSet'ioflow_rpg_characters.sarah_animSet'
                
        AnimTreeTemplate=AnimTree'ioflow_rpg_characters.sarah_animTree'
                
        SkeletalMesh=SkeletalMesh'ioflow_rpg_characters.sarah'
            
        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 
        If this doesn't work try to get a hold of online|offworld. He posted some code for showing a custom character so he may be able to help you out better then me.

        Comment


          #79
          Are you change World porpoties >>Game Type?

          followed on Hawk it's should work

          Comment


            #80
            Can anyon answer my question? How do u rotate the camera seperately from the pawn

            Comment


              #81
              i don't know about code anyway i recived this camera form Hawk


              but still refer to UTPlayerController can any one help?
              i want to change UTPlayerController to GamePlayerController
              when i change camera it's not working

              this is what i got
              class StayAliveInfo Extends GameInfo;

              DefaultProperties
              {

              bDelayedStart=false

              PlayerControllerClass = class 'StayAlive.StayAlivePlayerController' //Setting the Player Controller to your custom script

              DefaultPawnClass = class 'StayAlive.StayAlivePawn' //Setting the Pawn to your custom script
              }
              class StayAlivePawn Extends GamePawn;

              var float CamOffsetDistance; //distance to offset the camera from the player in unreal units
              var float CamMinDistance, CamMaxDistance;
              var float CamZoomTick; //how far to zoom in/out per command
              var float CamHeight; //how high cam is relative to pawn pelvis


              simulated function SetMeshVisibility(bool bVisible)
              {

              // Handle the main player mesh
              if (Mesh != None)
              {
              Mesh.SetOwnerNoSee(!bVisible);
              }


              }


              //override to make player mesh visible by default
              simulated event BecomeViewTarget( PlayerController PC )
              {
              local StayAlivePlayerController UTPC;

              Super.BecomeViewTarget(PC);

              if (LocalPlayer(PC.Player) != None)
              {
              UTPC = StayAlivePlayerController(PC);
              if (UTPC != None)
              {
              //set player controller to behind view and make mesh visible
              UTPC.SetBehindView(true);
              SetMeshVisibility(UTPC.bBehindView);

              //Show Crosshair = false, hide = true
              UTPC.bNoCrosshair = false;
              }
              }
              }

              simulated function FaceRotation(rotator NewRotation, float DeltaTime)
              {
              // Do not update Pawn's rotation if no accel
              if (Normal(Acceleration)!=vect(0,0,0))
              {
              if ( Physics == PHYS_Ladder )
              {
              NewRotation = OnLadder.Walldir;
              }
              else if ( (Physics == PHYS_Walking) || (Physics == PHYS_Falling) )
              {
              NewRotation = rotator((Location + Normal(Acceleration))-Location);
              NewRotation.Pitch = 0;
              }
              NewRotation = RLerp(Rotation,NewRotation,0.1,true);
              SetRotation(NewRotation);
              }

              }

              //orbit cam, follows player controller rotation
              simulated function bool CalcCamera( float fDeltaTime, out vector out_CamLoc, out rotator out_CamRot, out float out_FOV )
              {
              local vector HitLoc,HitNorm, End, Start, vecCamHeight;

              vecCamHeight = vect(-20,20,0);
              vecCamHeight.Z = CamHeight;
              Start = Location;
              End = (Location+vecCamHeight)-(Vector(Controller.Rotation) * CamOffsetDistance); //cam follow behind player controller
              out_CamLoc = End;

              //trace to check if cam running into wall/floor
              if(Trace(HitLoc,HitNorm,End,Start,false,vect(12,12 ,12))!=none)
              {
              out_CamLoc = HitLoc + vecCamHeight;
              }

              return true;
              }

              simulated function CamZoomIn()
              {
              if(CamOffsetDistance > CamMinDistance) CamOffsetDistance-=CamZoomTick;
              }

              simulated function CamZoomOut()
              {
              if(CamOffsetDistance < CamMaxDistance) CamOffsetDistance+=CamZoomTick;
              }

              defaultproperties
              {
              CamHeight = 30
              CamMinDistance = 20
              CamMaxDistance = 150.0
              CamOffsetDistance=120
              CamZoomTick=0

              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=false
              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_C H_Corrupt_Male_Physics'
              AnimSets(0)=AnimSet'SA-Character.Cartoon.Anim'
              AnimSets(1)=AnimSet'SA-Character.Cartoon.Anim'
              AnimTreeTemplate=AnimTree'SA-Character.Cartoon.AnimTree'
              SkeletalMesh=SkeletalMesh'SA-Character.Cartoon.Cartoon'
              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
              }
              this is UTPlayerController that i said
              i want to extends GamePlayerController and working too can any one help?
              class StayAlivePlayerController extends UTPlayerController;
              var bool bBehindView;
              var config bool bNoCrosshair;
              var bool bFreeCamera;
              var float LastCameraTimeStamp;

              //Update player rotation when walking
              state PlayerWalking
              {
              ignores SeePlayer, HearNoise, Bump;


              function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
              {
              local Vector tempAccel;
              local Rotator CameraRotationYawOnly;


              if( Pawn == None )
              {
              return;
              }

              if (Role == ROLE_Authority)
              {
              // Update ViewPitch for remote clients
              Pawn.SetRemoteViewPitch( Rotation.Pitch );
              }

              tempAccel.Y = PlayerInput.aStrafe * DeltaTime * 100 * PlayerInput.MoveForwardSpeed;
              tempAccel.X = PlayerInput.aForward * DeltaTime * 100 * PlayerInput.MoveForwardSpeed;
              tempAccel.Z = 0; //no vertical movement for now, may be needed by ladders later

              //get the controller yaw to transform our movement-accelerations by
              CameraRotationYawOnly.Yaw = Rotation.Yaw;
              tempAccel = tempAccel>>CameraRotationYawOnly; //transform the input by the camera World orientation so that it's in World frame
              Pawn.Acceleration = tempAccel;

              Pawn.FaceRotation(Rotation,DeltaTime); //notify pawn of rotation

              CheckJumpOrDuck();
              }
              }

              //Controller rotates with turning input
              function UpdateRotation( float DeltaTime )
              {
              local Rotator DeltaRot, newRotation, ViewRotation;

              ViewRotation = Rotation;
              if (Pawn!=none)
              {
              Pawn.SetDesiredRotation(ViewRotation);
              }

              // Calculate Delta to be applied on ViewRotation
              DeltaRot.Yaw = PlayerInput.aTurn;
              DeltaRot.Pitch = PlayerInput.aLookUp;

              ProcessViewRotation( DeltaTime, ViewRotation, DeltaRot );
              SetRotation(ViewRotation);

              NewRotation = ViewRotation;
              NewRotation.Roll = Rotation.Roll;

              if ( Pawn != None )
              Pawn.FaceRotation(NewRotation, deltatime); //notify pawn of rotation
              }

              exec function NextWeapon()
              {
              StayAlivePawn(Pawn).CamZoomOut();
              }

              exec function PrevWeapon()
              {
              StayAlivePawn(Pawn).CamZoomIn();
              }

              exec function BehindView()
              {
              if ( WorldInfo.NetMode == NM_Standalone )
              SetBehindView(!bBehindView);
              }

              function SetBehindView(bool bNewBehindView)
              {
              bBehindView = bNewBehindView;
              if ( !bBehindView )
              {
              bFreeCamera = false;
              }

              if (LocalPlayer(Player) == None)
              {
              ClientSetBehindView(bNewBehindView);
              }
              else if (UTPawn(ViewTarget) != None)
              {
              UTPawn(ViewTarget).SetThirdPersonCamera(bNewBehind View);
              }
              // make sure we recalculate camera position for this frame
              LastCameraTimeStamp = WorldInfo.TimeSeconds - 1.0;
              }

              reliable client function ClientSetBehindView(bool bNewBehindView)
              {
              if (LocalPlayer(Player) != None)
              {
              SetBehindView(bNewBehindView);
              }
              // make sure we recalculate camera position for this frame
              LastCameraTimeStamp = WorldInfo.TimeSeconds - 1.0;
              }


              DefaultProperties
              {

              }

              Comment


                #82
                Is the PlayerMoving part and after the part that makes the pawn rotate seperately from the camera?

                Comment


                  #83
                  Heya,

                  I've got a question regarding 3rd person camera views. I've got one setup (at first the one from the UDN camera tech guide) and it works flawless the first time i load the game. However when the pawn gets killed it reverts back to some sort of first person view, meaning i see the first person weapon again and the pawn mesh is hidden again.

                  For some reason feigning death makes the first person weapon dissapear and makes the pawn mesh visible again but i'm lost with how to make this happen properly when respawning.

                  So far i've tried a bucket of things but i've got the feeling i'm barking up the wrong tree.

                  I've put some log statements in the "BecomeViewTarget" of my Pawn but somehow i never see this logged (not even the first time) while it is being called in UTPawn (checked that with a log statement too).

                  Any help would be greatly appreciated, since all i need is a working 3rd person cam (which i have) that doesn't break on death.

                  Comment


                    #84
                    Alright,

                    nevermind it's fixed now, just gotta fix the mesh not hiding on respawn but i believe that has something to do with an ondeath event sort of thing.

                    Seemed my UDK install was messed up somehow, reinstalled and voila magical fix

                    Comment


                      #85
                      @Hawk: I'm using your version from here on this thread ( http://forums.epicgames.com/threads/...1#post29439219 ) and it works great but I think it could be expanded in a few useful ways.

                      If the camera functions were moved into a class extending Camera (or GamePlayerCamera ?) then it would be easy to take advantage of States so some timing tricks could be possible. It could be done within Pawn but it seems silly to have states there just for camera changes.

                      Some possibilities with States + sleep: A smooth transition moving the camera to a default position when Home is pressed. Or to hold down the PageUp / PageDown commands for Zoom In / Out rather than using the mousewheel. Or shaking the camera for a period of time. Or easing the camera transitions when the camera is moved while the player is standing still. -- You get the idea.

                      I'm going to attempt this myself, but I'm terrible with UnrealScript's scope so far (sooner or later it'll just "click" for me, I'm sure). So if anyone else comes up with the solution first, I'd be pleased to see it.

                      Comment


                        #86
                        Thanks syntaxerror22 for the codes. I'll study those codes.
                        And thanks to the guys whose improve the codes!
                        You are awesome!

                        Comment


                          #87
                          im using a custom camera so thats y i cant rotate my camera i guess. I m able to rotate the pawn and move around. Right now i c that in UpdateRotation u called ProcessViewRotation. Should i write Camera.ProcessViewRotation there and in my camera class i write the DeltaRot and NewRotation stuff there in my simulated function ProcessViewRotation so i can rotate the camera the same way as the pawn?

                          Comment


                            #88
                            Hey, So I have have been using my own camera somewhat based on the camera in the first post since the thread was first created.
                            But there's a problem with it.
                            I have a very burly character that's difficult to keep from blocking the view while still being visible, I just now saw Hawk's version which I believe would be perfect for solving this issue.

                            However, I am not extending the UTclasses. I can make the scripts compile just fine, the problem is that the SetBehindView bit isn't relevant to me, yet it seems to be vital to the camera to work.

                            Since the camera is already third person for me without the BecomeViewTarget function, I tried it without. However, the camera does not rotate or update the pawn rotation. The other coding works fine, as it's pretty much the same as the examples shown here already, with the exception of the camera controls.

                            Comment


                              #89
                              never mind actually. i hav my answer

                              Comment


                                #90
                                Hey there,

                                Firstly I'd like to say thanks for the awesome tutorial!

                                The only issue I'm experiencing is NOT with your camera code per se but the fact that its somehow conflicting with the previous code I had for forcing the game to spawn my custom character. I'm not a programmer by any means, in fact I've just been googling the script I want and so far I've fluked and everything has worked. Sadly the code I was using to force the game to use my custom character model also came with the functionality to switch to a 3rd person camera and I think this is where the conflict is happening. I tried to edit out the 3rd person code from that original script and managed to do so successfully, however its still spawning the default UDK Cathode model instead of mine.

                                Here's the original code I was using for my PlayerController:
                                Code:
                                class BDPlayerController extends UTPlayerController;
                                	
                                // members for the custom mesh
                                var SkeletalMesh defaultMesh;
                                var MaterialInterface defaultMaterial0;
                                //var MaterialInterface defaultMaterial1; (used for head and body material setup)
                                var AnimTree defaultAnimTree;
                                var array<AnimSet> defaultAnimSet;
                                var AnimNodeSequence defaultAnimSeq;
                                var PhysicsAsset defaultPhysicsAsset;
                                
                                simulated function PostBeginPlay() {
                                super.PostBeginPlay();
                                SetCameraMode('ThirdPerson');
                                resetMesh();
                                }
                                // Sets the Pawns Mesh to the resources specified in the Default Properties
                                public function resetMesh(){
                                self.Pawn.Mesh.SetSkeletalMesh(defaultMesh);
                                self.Pawn.Mesh.SetMaterial(0,defaultMaterial0);
                                //self.Pawn.Mesh.SetMaterial(1,defaultMaterial1);
                                self.Pawn.Mesh.SetPhysicsAsset(defaultPhysicsAsset );
                                self.Pawn.Mesh.AnimSets=defaultAnimSet;
                                self.Pawn.Mesh.SetAnimTreeTemplate(defaultAnimTree );
                                }
                                
                                // Called at RestartPlayer by GameType
                                public function rSetBehindView(bool view){
                                SetBehindView(view);
                                }
                                // Called at RestartPlayer by GameType
                                public function rSetCameraMode(name cameraSetting){
                                SetCameraMode(cameraSetting);
                                }
                                	
                                event Possess(Pawn inPawn, bool bVehicleTransition)
                                {
                                	Super.Possess(inPawn, bVehicleTransition);
                                	SetBehindView(true);	
                                }
                                
                                defaultproperties
                                {
                                	Name="Default__BDPlayerController"
                                	defaultMesh=SkeletalMesh'BD_Strider.Meshes.SK_CH_Strider'
                                	defaultMaterial0=MaterialInstanceConstant'BD_Strider.Materials.MI_CH_Strider'
                                	//defaultMaterial1=Material'MyPackage.SATSC_Characters.Hellgrim_Body_Material'
                                	defaultAnimTree=AnimTree'BD_Strider.AnimTree.AT_CH_Strider'
                                	defaultAnimSet(0)=AnimSet'BD_Strider.Anims.AS_CH_Strider'
                                	defaultPhysicsAsset=PhysicsAsset'BD_Strider.Meshes.SK_CH_Strider_Physics'
                                }
                                As you can see, this causes the default mesh to be replaced by my custom mesh and also switches to the default UDK 3rd person camera.

                                Now here's the tweaked code I've used to include your camera and remove the camera in this script and what I was hoping would ALSO allow my custom mesh to load:
                                Code:
                                class BDPlayerController extends UTPlayerController;
                                	
                                // members for the custom mesh
                                var SkeletalMesh defaultMesh;
                                var MaterialInterface defaultMaterial0;
                                //var MaterialInterface defaultMaterial1; (used for head and body material setup)
                                var AnimTree defaultAnimTree;
                                var array<AnimSet> defaultAnimSet;
                                var AnimNodeSequence defaultAnimSeq;
                                var PhysicsAsset defaultPhysicsAsset;
                                	
                                //Start Third Person Camera Control
                                //Update player rotation when walking
                                state PlayerWalking
                                {
                                ignores SeePlayer, HearNoise, Bump;
                                
                                
                                   function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
                                   {
                                	  local Vector tempAccel;
                                		local Rotator CameraRotationYawOnly;
                                		
                                
                                      if( Pawn == None )
                                      {
                                         return;
                                      }
                                
                                      if (Role == ROLE_Authority)
                                      {
                                         // Update ViewPitch for remote clients
                                         Pawn.SetRemoteViewPitch( Rotation.Pitch );
                                      }
                                
                                      tempAccel.Y =  PlayerInput.aStrafe * DeltaTime * 100 * PlayerInput.MoveForwardSpeed;
                                      tempAccel.X = PlayerInput.aForward * DeltaTime * 100 * PlayerInput.MoveForwardSpeed;
                                      tempAccel.Z = 0; //no vertical movement for now, may be needed by ladders later
                                      
                                	 //get the controller yaw to transform our movement-accelerations by
                                	CameraRotationYawOnly.Yaw = Rotation.Yaw; 
                                	tempAccel = tempAccel>>CameraRotationYawOnly; //transform the input by the camera World orientation so that it's in World frame
                                	Pawn.Acceleration = tempAccel;
                                   
                                	Pawn.FaceRotation(Rotation,DeltaTime); //notify pawn of rotation
                                
                                    CheckJumpOrDuck();
                                   }
                                }
                                
                                //Controller rotates with turning input
                                function UpdateRotation( float DeltaTime )
                                {
                                local Rotator   DeltaRot, newRotation, ViewRotation;
                                
                                   ViewRotation = Rotation;
                                   if (Pawn!=none)
                                   {
                                      Pawn.SetDesiredRotation(ViewRotation);
                                   }
                                
                                   // Calculate Delta to be applied on ViewRotation
                                   DeltaRot.Yaw   = PlayerInput.aTurn;
                                   DeltaRot.Pitch   = PlayerInput.aLookUp;
                                
                                   ProcessViewRotation( DeltaTime, ViewRotation, DeltaRot );
                                   SetRotation(ViewRotation);
                                
                                   NewRotation = ViewRotation;
                                   NewRotation.Roll = Rotation.Roll;
                                
                                   if ( Pawn != None )
                                      Pawn.FaceRotation(NewRotation, deltatime); //notify pawn of rotation
                                }   	
                                //End Third Person Camera Control	
                                
                                // Sets the Pawns Mesh to the resources specified in the Default Properties
                                public function resetMesh(){
                                self.Pawn.Mesh.SetSkeletalMesh(defaultMesh);
                                self.Pawn.Mesh.SetMaterial(0,defaultMaterial0);
                                //self.Pawn.Mesh.SetMaterial(1,defaultMaterial1);
                                self.Pawn.Mesh.SetPhysicsAsset(defaultPhysicsAsset );
                                self.Pawn.Mesh.AnimSets=defaultAnimSet;
                                self.Pawn.Mesh.SetAnimTreeTemplate(defaultAnimTree );
                                }
                                
                                defaultproperties
                                {
                                	Name="Default__BDPlayerController"
                                	defaultMesh=SkeletalMesh'BD_Strider.Meshes.SK_CH_Strider'
                                	defaultMaterial0=MaterialInstanceConstant'BD_Strider.Materials.MI_CH_Strider'
                                	//defaultMaterial1=Material'MyPackage.SATSC_Characters.Hellgrim_Body_Material'
                                	defaultAnimTree=AnimTree'BD_Strider.AnimTree.AT_CH_Strider'
                                	defaultAnimSet(0)=AnimSet'BD_Strider.Anims.AS_CH_Strider'
                                	defaultPhysicsAsset=PhysicsAsset'BD_Strider.Meshes.SK_CH_Strider_Physics'
                                }
                                Unfortunately it compiles without errors or warnings, but when I spawn in my custom map, its using Cathode again. Any idea what changes I need to make to get both playing nicely together?

                                Thanks!

                                Comment

                                Working...
                                X