Announcement

Collapse

The Infinity Blade Forums Have Moved

We've launched brand new Infinity Blade forums with improved features and revamped layout. We've also included a complete archive of the previous posts. Come check out the new Infinity Blade forums.
See more
See less

UDK action game - 3rd person camera code

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

    #31
    I have silly question ... any additional work on DefaultGame.ini or DefaultEngine.ini ?

    Thanks

    Comment


      #32
      Ok, I've finaly get it to work. After a lot of modification, everything else than my weapons and huds are working, Thanks a lot for the script :P

      Comment


        #33
        I got a silly (noob) question, Trying out your script while struggling to understand, I noticed that when moving or aiming to any side, the pawn will simply fire while the actual shot goes where the camera is aiming.

        I've tried to fix that by trying 2 things, 1 is to rotate the pawn to the position the camera is aiming, and the other is to rotate the camera to where the pawn was aiming, which I failed in both of them (funny but sad).

        anyway, Since the idea is to do any rotation while firing, I came up with this in Playercontroller.uc (the new one, or the one created for this camera)

        Code:
        exec function StartFire( optional byte FireModeNum )
        {
        	local rotator ViewAim;
        	`Log("Hoorray I didn't catch fire!");
        	ViewAim = Pawn.Rotation;
        	ViewAim.yaw +=10000;
        	pawn.setrotation(ViewAim);
        	super.StartFire(FireModeNum);
        }
        that one rotates the pawn by 10000 unreal units which is aprox 55ยบ if i'm not mistaken. Anyway, I'm failing at getting the current camera yaw to set it as pawn.setrotation, which I know it's stupid since I have the code and calculation before my eyes XD

        Excuse me for my ugly english, and for this question indeed, it's embarrassing, but i'm close to get 2 weeks old with UDK.

        P.S. I've found the Pawn.Rotation + Pawn.SetRotation stuff in these forums.

        Log:
        Code:
        [0073.76] Cmd: StartFire 
        [0073.77] ScriptLog: Hoorray I didn't catch fire!
        [0073.77] Cmd: OnRelease StopFire
        Thanks in advance.

        Comment


          #34
          Awesome work dude, finally got my character and camera working the way I wanted.
          Now to figure out how to do shooting with this and a custom character...

          Comment


            #35
            Hi Syntaxerror22,

            I made some tweaks to your code and thought I should contribute them back to everyone as I'd never have been able to get this going if you hadn't done the same.

            Along those lines - to everyone else - please be aware that I don't understand all of the code in these scripts and probably won't be able to help anyone who has questions about the bits I didn't change.

            My changes are small but hopefully useful:
            - I extended from more basic classes for a smaller footprint
            - I put a custom mesh on the pawn (you'll need to adjust this for yours)
            - Zoom in/out is hooked up to the mousewheel
            - Pawn changes direction smoothly depending on w,a,s,d

            MyGameInfo.uc
            Code:
            class MyGameInfo extends FrameworkGame;
            
            defaultproperties
            {
            	PlayerControllerClass=class'ioflow_rpg.ActionPlayerController'
            	DefaultPawnClass=class'ioflow_rpg.ActionPawn'
            	bDelayedStart=false
            }
            ActionPawn.uc
            Code:
            class ActionPawn extends Pawn;
            
            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 event PostBeginPlay()
            {
            	super.PostBeginPlay();
            	`Log("Custom Pawn up"); //debug
            
            }
            
            //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 = false;
                  }
               }
            }
            
            //only update pawn rotation while moving
            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(0,0,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;
            	}
            	
            	//camera will look slightly above player
               out_CamRot=rotator((Location + vecCamHeight) - out_CamLoc);
               return true;
            }
            
            simulated function CamZoomIn()
            {
            	if(CamOffsetDistance > CamMinDistance)		CamOffsetDistance-=CamZoomTick;
            }
            
            simulated function CamZoomOut()
            {
            	if(CamOffsetDistance < CamMaxDistance) 	CamOffsetDistance+=CamZoomTick;
            }
            
            defaultproperties
            {
            	CamHeight = 40.0
            	CamMinDistance = 40.0
            	CamMaxDistance = 350.0
              CamOffsetDistance=250.0
            	CamZoomTick=20.0	
            	
            	//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
            }
            ActionPlayerController.uc
            Code:
            class ActionPlayerController extends PlayerController;
            
            //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() 
            {
            	ActionPawn(Pawn).CamZoomOut();
            }
            
            exec function PrevWeapon() 
            {
            	ActionPawn(Pawn).CamZoomIn();
            }
            
            DefaultProperties
            {
                
            }

            Comment


              #36
              @online|offworld

              You are awsome! I just tried the code and it is working plus the pawn's diagonal movement is no longer restricted when camera is above it.Can I use the code?

              PS - How did you do smooth rotation?

              Comment


                #37
                LazySnake61 (and anyone else) regarding code use, of course, go for it, it's not even really mine

                I saw someone else talking about using RInterp to interpolate, and that part of their code was similar to a part in this script so I tried it there and it worked I can't remember who it was though sorry, I've been through SO many camera snippets on the weekend I lost count...

                Comment


                  #38
                  I also have a noob q.

                  I am not sure how to implement these subclasses as MyGameInfo extends UTDeathmatch. Editing my files gives compilation errors which means my patchwork knowledge isnt enough.

                  Do these subclasses go in our Development/Src/MyGame/Classes alongside the already excisting MyPawn, MyPlayerController ?
                  I got my character into the editor by changing values/refs in the Development/Src/UTGame/classes.

                  Any help appreciated.
                  Cheers

                  Comment


                    #39
                    hey this code is very useful but i only need the cam zoom in and out bits any chance you could repost the coding but then put the ones needing for the zooming/out in bold so i can use that because im finding a hard time trying this, i might bemissing stuff

                    thanks

                    Comment


                      #40
                      Code:
                      exec function CamZoomIn()
                      {
                      	`Log("Zoom in");
                      	if(CamOffsetDistance > CamMinDistance)
                      		CamOffsetDistance-=CamZoomTick;
                      }
                      
                      exec function CamZoomOut()
                      {
                      	`Log("Zoom out");
                      	if(CamOffsetDistance < CamMaxDistance)
                      		CamOffsetDistance+=CamZoomTick;
                      }
                      this code gives me errors as it says :
                      bad or missing expression in 'if'
                      bad or missing expression for token : CamOffsetDistance, in IF
                      am i missing something here?

                      EDIT: dont worry i ve sorted this, i just forgot to add the variable at the start for CamOffsetDistance lol ...

                      Comment


                        #41
                        omg im still not getting the mousewheel up and down working i have it in the default input and get no errors but still nothing the camera just stays still :/

                        Comment


                          #42
                          There is small glitch.When camera orbits extremely above pawn,it goes past that point and becomes upside down.

                          Comment


                            #43
                            Originally posted by JmPrsh153 View Post
                            Code:
                            exec function CamZoomIn()
                            {
                            	`Log("Zoom in");
                            	if(CamOffsetDistance > CamMinDistance)
                            		CamOffsetDistance-=CamZoomTick;
                            }
                            
                            exec function CamZoomOut()
                            {
                            	`Log("Zoom out");
                            	if(CamOffsetDistance < CamMaxDistance)
                            		CamOffsetDistance+=CamZoomTick;
                            }
                            this code gives me errors as it says :


                            am i missing something here?

                            EDIT: dont worry i ve sorted this, i just forgot to add the variable at the start for CamOffsetDistance lol ...
                            These things tend to be a house of cards, you can't just pull a couple of cards out of it then say OMG they won't stand up. Try instead implementing the script I've provided in it's entirety, then carefully removing a little bit at a time until it stops working. Then you'll know which bits you can take out without breaking it and which bits you can't.

                            Comment


                              #44
                              hey do ou know how to make a looping sound stop at a certain point in uscript?

                              Comment


                                #45
                                In my classes folder I copied the code sheets. I changed config files to reflect the new subclasses and am still getting these compile errors.

                                Code:
                                Warning/Error Summary
                                ---------------------
                                C:\UDK\UDK-2011-06\Development\Src\RDGame\Classes\ActionPawn.uc(90) : Error, Unexpected 'ActionPlayerController'
                                C:\UDK\UDK-2011-06\Development\Src\RDGame\Classes\ActionPlayerController.uc(77) : Error, Unexpected '__________________'
                                Ok, the first one is just a {
                                These are copy paste from here.

                                The second one is a
                                {
                                }
                                with nothing in between, is there something that is supposed to go there?

                                Would love to get this working.
                                Cheers

                                Ha ha, now it works. Very impressive!

                                Comment

                                Working...
                                X