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

3rd Person Camera - Code

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

    3rd Person Camera - Code

    There is some requests about 3rd person cam. From simply code to how to make it.
    Here is code from my mutator to UT3. Modified to work with UDK.
    If you want to try out it, you can just fallow basic game tutorial by Hourences (simply override CalcCamera code in MyPawn.uc).

    Code:
    var() float CameraOffsetLength;
    var float CurrentCameraDistance, CurrentCameraOffsetLength;
    
    simulated function bool CalcCamera(float fDeltaTime, out vector out_CamLoc, out rotator out_CamRot, out float out_FOV)
    {
    	local vector CamStart, FirstHitLocation, HitLocation, HitNormal, CamDir, X, Y, Z;
    	local float DesiredCameraZOffset;
    	local bool bInsideHero, bObstructed;
    
    		local float DesiredCameraDistance;
    		    local float CameraOffsetRatio;
    	local vector tempCamStart, tempCamEnd;
    	local Vector VectorX, VectorY, VectorZ;
    
    	bObstructed = false;
    
    	//Mesh.SetOwnerNoSee(false);
    
    	// Handle the fixed camera
    	if (bFixedView)
    	{
    		out_CamLoc = FixedViewLoc;
    		out_CamRot = FixedViewRot;
    	}
    
    	ModifyRotForDebugFreeCam(out_CamRot);
    
    	CamStart = Location;
    	DesiredCameraZOffset = (Health > 0) ? GetCollisionRadius() * 0.75 : 0.f;
    	CameraZOffset = (fDeltaTime < 0.2) ? DesiredCameraZOffset * 5 * fDeltaTime + (1 - 5*fDeltaTime) * CameraZOffset : DesiredCameraZOffset;
    
    	CamStart.Z += CameraZOffset;
    	GetAxes(out_CamRot, X, Y, Z);
    /*VectorX here you can implement camera zoom in/out or scaling or whatever you want to call it */
    		VectorX = X * GetCollisionRadius() * 4.2; //this vector determine depth of camera, how far from character it will be
    
    		VectorY = Y * GetCollisionRadius() * -1.9f; // this vector determine side of camera, negaive value pull character to left side, while positive to right side
    		VectorZ = (GetCollisionRadius() /* FMax(0,(1.0-CamRotZ.Z))*/ * Z) * -1.55; //this value try to pull camera forward while pitching down, and back while pitching up, but pulling back seems to dont work
    		CamDir = VectorX + VectorY + VectorZ;
    
    	if ( (Health <= 0) || bFeigningDeath )
    	{
    		// adjust camera position to make sure it's not clipping into world
    		// @todo fixmesteve.  Note that you can still get clipping if FindSpot fails (happens rarely)
    		FindSpot(GetCollisionExtent(),CamStart);
    	}
    	/*
    	if (CurrentCameraScale < CameraScale)
    	{
    		CurrentCameraScale = FMin(CameraScale, CurrentCameraScale + 5 * FMax(CameraScale - CurrentCameraScale, 0.3)*fDeltaTime);
    	}
    	else if (CurrentCameraScale > CameraScale)
    	{
    		CurrentCameraScale = FMax(CameraScale, CurrentCameraScale - 5 * FMax(CameraScale - CurrentCameraScale, 0.3)*fDeltaTime);
    	}*/
    	if (CamDir.Z <= GetCollisionHeight())
    	{
    		CamDir *= square(cos(out_CamRot.Pitch * 0.000000958738)); // 0.0000958738 = 2*PI/65536
    	}
    
    	out_CamLoc = CamStart - CamDir;
    
    	if (Trace(HitLocation, HitNormal, out_CamLoc, CamStart, false, vect(12,12,12)) != None)
    	{
    		out_CamLoc = HitLocation;
    		bObstructed = true;
    	}
    
    
    
    			/* This code is from ActionGam, thanks for fall, for creating this. 
    		 * It will determine back trace collision while closing to walls or sth like thaht*/
    		if (Trace(HitLocation, HitNormal, out_CamLoc, CamStart, false, vect(12,12,12),,TRACEFLAG_Blocking) != None)
    		{
        		DesiredCameraDistance = VSize(HitLocation-CamStart);
        		CurrentCameraDistance = (fDeltaTime < 0.5f) ? FClamp(DesiredCameraDistance * 2 * fDeltaTime + (1 - 2*fDeltaTime) * CurrentCameraDistance,0,DesiredCameraDistance) : DesiredCameraDistance;
    
        		HitLocation = CamStart + Normal(HitLocation-CamStart) * CurrentCameraDistance;
    
    			CameraOffsetRatio = CurrentCameraDistance/VSize(out_CamLoc - CamStart);
    			out_CamLoc = HitLocation;
    			bObstructed = true;
    		}
    
    		else
    		{
        		DesiredCameraDistance = VSize(out_CamLoc-CamStart);
        		CurrentCameraDistance = (fDeltaTime < 0.5f) ? FClamp(DesiredCameraDistance * 2 * fDeltaTime + (1 - 2*fDeltaTime) * CurrentCameraDistance,0,DesiredCameraDistance) : DesiredCameraDistance;
    
    			HitLocation = CamStart + Normal(out_CamLoc - CamStart) * CurrentCameraDistance;
    
    			CameraOffsetRatio = CurrentCameraDistance/VSize(out_CamLoc - CamStart);
    			out_CamLoc = HitLocation;
    		}
    
    		if (Trace(HitLocation, HitNormal, out_CamLoc, CamStart, false, vect(12,12,12)) != None)
    		{
    			out_CamLoc = HitLocation;
    			return false;
    		}
    		
    		/*Again thanks for fall, for this. It just inside character collision detection*/
    		tempCamStart = CamStart;
    		tempCamStart.Z = 0;
    		tempCamEnd = out_CamLoc;
    		tempCamEnd.Z = 0;
    
    		if(bObstructed && (VSize(tempCamEnd - tempCamStart) < CylinderComponent.CollisionRadius*1.25) && (out_CamLoc.Z<Location.Z+CylinderComponent.CollisionHeight) && (out_CamLoc.Z>Location.Z-CylinderComponent.CollisionHeight))
    		{
    			SetHidden(true);
    		}
    		else
    			SetHidden(false);
    
    		return !bObstructed;
    }
    This is quite basic. There is no scaling of offsets based on FOV there is also no guarantee this will actually works.. (strange thing first time i run it, it simply doesn't work, then i just copy-paste code from UTHeroPawn (Mutator), and replaced everything from pasted code and it started to work, I still have no idea why ;o).

    I post updates here (if they come), but by any means, feel free to use it.

    #2
    Thanks inside, I didn't think it would work because of these warnings, but in game it works fine. All I need now is a chase cam once again thanks.
    Code:
    Warning/Error Summary
    ---------------------
    C:\UDK\UDK-2009-11-2\Development\Src\MyGame\Classes\MyPawn.uc(8) : Warning, 'FirstHitLocation' : unreferenced local variable
    C:\UDK\UDK-2009-11-2\Development\Src\MyGame\Classes\MyPawn.uc(10) : Warning, 'bInsideHero' : unreferenced local variable
    C:\UDK\UDK-2009-11-2\Development\Src\MyGame\Classes\MyPawn.uc(82) : Warning, 'CameraOffsetRatio' : unused local variable
    
    Success - 0 error(s), 3 warning(s)
    Execution of commandlet took:  26.86 seconds
    
    [COMMANDLET 'UDK.exe make -full' SUCCEEDED] November 25, 5:13 AM

    Comment


      #3
      Chasing code is very simple to get, I will post updated code with comments.

      Comment


        #4
        Any insight as to how to make the camera shake? Kinda like Gears of War.

        Comment


          #5
          Great, thank you fpr posting the code. Need that one.

          Comment


            #6
            really nice contribution

            Comment


              #7
              Thanks for sharing this!

              Comment


                #8
                Hi

                i wanted to know someone can help me with camera on my vehicle, i have the camera all i wanna do is remove the mouse control from that camera so that the camera follows the vehicle something like in racing games

                Comment


                  #9
                  Nicely done camera, iniside. I've been playing with the code you posted and modifying it some for the sake of seeing what I can do with it, and have to admit it's helped me learn some stuff about the nature of the default camera settings. (I'm a decent coder, but working with vectors and 3D environments is new for me.)
                  Something I've been trying to fiddle with, however, would be to produce an offset to the camera's starting position along the horizontal plane. The Z-axis code is already included in the default code (seeing as how your code here takes a lot from the default third person camera setup), but trying to get the formula right for the X/Y axes is proving to be a challenge. In your creation of this code or any of your work so far, have you played with anything along the same lines that you could point me towards? Much appreciated.

                  Comment


                    #10
                    i ve one question .... when i ve cinematiq i ve some troubles .... the body isn't shown any more ... http://www.youtube.com/watch?v=DMD1rxPhyZk this is what i am talking about

                    Comment


                      #11
                      In Kismet you must make sure you run ToggleCinematicMode again when the sequence is finished with the option to show the character toggled on.

                      Comment


                        #12
                        how exactly ?? http://zapodaj.net/f7640b097503.bmp.html

                        Comment


                          #13
                          I just use console command with the behindview command

                          Comment


                            #14
                            dude
                            cinematic mode needs to be "enabled" before the matinee begins, then when the matinee has finished it needs to be "disbaled"
                            u can do it like this

                            Trigger -> Matinee [play] + CinematicMode [enabled]

                            Matinee [completed] -> CinematicMode [disbale]


                            if you select Cinematic node in kismet, theres some properties at the bottom, but only use this if you wana hide the player/ you could show a video, and have the player allowed to run around still

                            Comment


                              #15
                              I finally got this code implemented and working. Great contribution!!! How would I accomplish getting it offset like GoW? I've been tinkering with it but I'm no coder. I'm a noob I've searched around but haven't been able to find anything on the forums or web.

                              Comment

                              Working...
                              X