Announcement

Collapse
No announcement yet.

Unreal Camera and HUD

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

    Unreal Camera and HUD

    I have run through most of the tutorials I have found online but I am still having problems getting my custom HUD and camera to work together. I have serveral classes built and all are extending a UTclass. When I do this my HUD works but my camera stops working, the game just uses the default camera. When I extend everything from the base classes (i.e. MyPawn extends GamePawn) my camera works but my HUD doesn't.

    This is MyPawn class

    Code:
    class MyPawn extends UTPawn
    	config(Game);
    
    	
    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() * 10; //this vector determine depth of camera, how far from character it will be
    
    		VectorY = Y * GetCollisionRadius() * 0; // 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 (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;
    }
    
    defaultproperties
    {
    	
    
        Begin Object Class=SkeletalMeshComponent Name=InitialSkeletalMesh
    		CastShadow=true
    		bCastDynamicShadow=true
    		bOwnerNoSee=false
    		LightEnvironment=MyLightEnvironment;
            BlockRigidBody=true;
            CollideActors=true;
            BlockZeroExtent=true;
    		PhysicsAsset=PhysicsAsset'CH_AnimCorrupt.Mesh.SK_CH_Corrupt_Male_Physics'
    		AnimSets(0)=AnimSet'CH_AnimHuman.Anims.K_AnimHuman_AimOffset'
    		AnimSets(1)=AnimSet'CH_AnimHuman.Anims.K_AnimHuman_BaseMale'
    		AnimTreeTemplate=AnimTree'CH_AnimHuman_Tree.AT_CH_Human'
    		SkeletalMesh=SkeletalMesh'CH_LIAM_Cathode.Mesh.SK_CH_LIAM_Cathode'
    	End Object
    
    	Mesh=InitialSkeletalMesh;
    	Components.Add(InitialSkeletalMesh);
    }

    This is MyPlayerController class

    Code:
    class MyPlayerController extends UTPlayerController
    	config(Game);
    	
    
    
    function UpdateRotation( float DeltaTime )
    {
    	local Rotator	DeltaRot, ViewRotation;
    
    	ViewRotation = Rotation;	
    
    	DeltaRot.Yaw = PlayerInput.aTurn;
    	DeltaRot.Pitch	= PlayerInput.aLookUp;
    
    	ProcessViewRotation( DeltaTime, ViewRotation, DeltaRot );
    
    	SetRotation(ViewRotation);
    
    	Pawn.FaceRotation(ViewRotation, DeltaTime);
    }
    
    	//BEING EDIT-----
    	// Calculate Delta to be applied on ViewRotation
    	//DeltaRot.Yaw	= PlayerInput.aTurn;
    	//DeltaRot.Pitch	= PlayerInput.aLookUp;
    
    	
    	
    
    
    
    event PlayerTick( float DeltaTime )
    {
    	local int x,y;
    
    	super.PlayerTick(DeltaTime);
    
    	class'UIRoot'.static.GetCursorPosition( x, y );
    	`Log("Mouse pos X" @ x @ "Mouse pos Y" @ y);
    }
    
    defaultproperties
    {
    	CameraClass=class'ShadowGame.MyPlayerCamera'	
    }
    This is my MyGameInfo class

    Code:
    class MyGameInfo extends UTGame;
    
    defaultproperties
    {
    	bDelayedStart = false;
    	PlayerControllerClass=class 'UTGame.UTPlayerController'
    	DefaultPawnClass=class 'ShadowGame.MyPawn'
    	
    	
    	Name="Default_MyGameInfo"
    	HUDType = class'ShadowGame.MyHUD';
    }
    This is MyHUD class

    Code:
    class MyHUD extends UTHUD;
    
    	//Canvas.Font = class'Engine'.static.GetSmallFont();
    	//Canvas.Font = class'Engine'.static.GetMediumFont();
    	//Canvas.Font = class'Engine'.static.GetLargeFont();
    
    function DrawGameHud()
    {
    	if(!PlayerOwner.IsDead() && !UTPlayerOwner.IsInState('Spectating'))
    	{
    		DrawBar("Health", 200, PlayerOwner.Pawn.HealthMax, 20,20,0,0,0);
    		DrawBar("Health", PlayerOwner.Pawn.Health, 
    				PlayerOwner.Pawn.HealthMax, 20, 20, 200, 80, 80);
    		/*DrawBar("Ammo", UTWeapon(PawnOwner.Weapon).AmmoCount, 
    	UTWeapon(PawnOwner.Weapon).MaxAmmoCount , 20, 40, 80, 80, 200);*/
    	}
    }
    
    function DrawBar(String Title, float Value, float MaxValue, int X, int Y, int R, int G, int B)
    {
    	local int PosX, NbCases, i;
    
    	PosX = X; //where we should draw the next rectangle.
    	NbCases = 100 * Value / MaxValue; // Number of active rectangles to draw
    	i = 0; // Number of rectangles already drawn.
    
    	/*Displays active rectangles*/
    	while(i < NbCases && i < 100)
    	{
    		Canvas.SetPos(PosX + 450, Y + 700);
    		Canvas.SetDrawColor(R,G,B, 200);
    		Canvas.DrawRect(2,30);
    
    		PosX += 2;
    		i++;
    	}
    	
    	/*Displays a title*/
    	/*Canvas.SetPos(PosX + 5,Y);
    	Canvas.SetDrawColor(R,G,B,200);
    	Canvas.Font = class'Engine'.static.GetSmallFont();
    	Canvas.DrawText("Title");*/ 
    }
    
    DefaultProperties
    {
    }
    Here is MyPlayerCameraClass

    Code:
    class MyPlayerCamera extends GamePlayerCamera;
    
    protected function GameCameraBase FindBestCameraType(Actor CameraTarget)
    {
    	return ThirdPersonCam;	
    }
    
    defaultproperties
    {
    	ThirdPersonCameraClass=class'ShadowGame.MyThirdPersonCamera'	
    }
    Here is the Camera Defaults class

    Code:
    class MyThirdPersonCameraMode_Default extends GameThirdPersonCameraMode_Default;
    
    var float FOV;
    
    function float GetDesiredFOV( Pawn ViewedPawn )
    {
    	return FOV;	
    }
    
    DefaultProperties
    {
    	FOV=100.0f
    	TargetRelativeCameraOriginOffset=(x= -70,y=-30,z=0)
    	bLockedToViewTarget=TRUE
    	bFollowTarget=FALSE
    	bInterpLocation=TRUE
    	bInterpRotation=TRUE
    	bSkipCameraCollision=false
    	BlendTime=0.75	
    }

    Right now only the Hud works and it defaults to the main third person cam not mine. I know this is a lot of code but I am at a complete loss as to why this isn't working. Any help would be much appreciated. Thanks.
Working...
X