PDA

View Full Version : 3rd person camera zoom?



3Dforlife
05-07-2010, 06:56 PM
I want know where in this code, and what (to do),for make in my game the camera zoom in, and out by clicking a mouse button?


class MyPawn extends UTPawn;

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;
}

peam
05-08-2010, 03:18 AM
In normal code, you can change:
CameraScale

And it will change zoom level smoothly.
(However, in your code it was commented out)