Announcement

Collapse
No announcement yet.

3rd Person Camera - Code

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

  • replied
    really nice contribution

    Leave a comment:


  • replied
    Great, thank you fpr posting the code. Need that one.

    Leave a comment:


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

    Leave a comment:


  • replied
    Chasing code is very simple to get, I will post updated code with comments.

    Leave a comment:


  • replied
    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

    Leave a comment:


  • started a topic 3rd Person Camera - Code

    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.
Working...
X