Hey guys !
I am trying to get a 3rd person camera which can be able to aim my character up and down, exactly like this : [ame="
http://www.youtube.com/watch?v=U6zgXWho5sY"]UDK Custom 3rd Person Camera - YouTube[/ame]
My code allows me to move my character the way I want, but when I look up for example, I want my pawn to look up aswell, and my code doesn't have this functionality, and don't know how to implement that... I searched many 3rd person code but none of them allow to get a working up and down aiming system.
This is my code :
CthulhuPawn.uc :
class CthulhuPawn extends Pawn;
var DynamicLightEnvironmentComponent LightEnvironment;
var SkeletalMeshComponent MyMeshComponent;
var PlayerFlashlight Flashlight;
var PlayerFlashlight2 Flashlight2;
var StaticMeshComponent MyVolumic;
var StaticMeshComponent MyVolumic2;
simulated function PostBeginPlay()
{
Flashlight = Spawn(class'PlayerFlashlight', self);
Flashlight.SetBase(self);
Flashlight.LightComponent.CastDynamicShadows = true;
Flashlight.LightComponent.SetEnabled(true);
`log("Flashlight Spawned!");
Flashlight.LightComponent.SetLightProperties(8);
Flashlight2 = Spawn(class'PlayerFlashlight2', self);
Flashlight2.SetBase(self);
Flashlight2.LightComponent.CastDynamicShadows = true;
Flashlight2.LightComponent.SetEnabled(true);
`log("Flashlight2 Spawned!");
Flashlight2.LightComponent.SetLightProperties(8);
MyMeshComponent.AttachComponentToSocket(FlashLight.LightComponent, 'WeaponPoint');
MyMeshComponent.AttachComponentToSocket(FlashLight2.LightComponent, 'WeaponPoint');
MyMeshComponent.AttachComponentToSocket(MyVolumic, 'WeaponPoint');
MyMeshComponent.AttachComponentToSocket(MyVolumic2, 'WeaponPoint');
super.PostBeginPlay();
}
//------------------------------------------------------------------------------
// ToggleFlashlight()
//------------------------------------------------------------------------------
exec function ToggleFlashlight()
{
if(!Flashlight.LightComponent.bEnabled)
{
Flashlight.LightComponent.SetEnabled(true);
Flashlight2.LightComponent.SetEnabled(true);
MyVolumic.setHidden (false);
MyVolumic2.setHidden (false);
}
else
{
Flashlight.LightComponent.SetEnabled(false);
Flashlight2.LightComponent.SetEnabled(false);
MyVolumic.setHidden (true);
MyVolumic2.setHidden (true);
}
}
event UpdateEyeHeight( float DeltaTime )
{
Flashlight.SetRotation(Controller.Rotation);
}
defaultproperties
{
WalkingPct=+0.4
CrouchedPct=+0.4
BaseEyeHeight=38.0
EyeHeight=38.0
GroundSpeed=440.0
AirSpeed=440.0
WaterSpeed=220.0
AccelRate=2048.0
JumpZ=322.0
CrouchHeight=29.0
CrouchRadius=21.0
WalkableFloorZ=0.78
Components.Remove(Sprite)
Begin Object Class=StaticMeshComponent Name=MyVolumicc2
CastShadow=true
bCastDynamicShadow=true
bOwnerNoSee=false
StaticMesh=StaticMesh'MyPackage.Hou_Vol1'
End Object
MyVolumic2=MyVolumicc2
Begin Object Class=StaticMeshComponent Name=MyVolumicc
CastShadow=true
bCastDynamicShadow=true
bOwnerNoSee=false
StaticMesh=StaticMesh'MyPackage.Hou_Vol'
End Object
MyVolumic=MyVolumicc
Begin Object Class=DynamicLightEnvironmentComponent Name=MyLightEnvironment
bSynthesizeSHLight=TRUE
bIsCharacterLightEnvironment=TRUE
bUseBooleanEnvironmentShadowing=FALSE
End Object
Components.Add(MyLightEnvironment)
LightEnvironment=MyLightEnvironment
Begin Object Class=SkeletalMeshComponent Name=WPawnSkeletalMeshComponent
//SkeletalMesh=SkeletalMesh'MyPackage.Journalist'
//AnimTreeTemplate=AnimTree'MyPackage.Journalist_AnimTree'
//AnimSets(0)=AnimSet'MyPackage.Journalist_AnimSet'
//SkeletalMesh=SkeletalMesh'MyPackage.Female.Human_Athletic'
//AnimTreeTemplate=AnimTree'MyPackage.Female.Human_Athletic_AnimTree'
// AnimSets(0)=AnimSet'MyPackage.Female.Human_Athletic_AnimSet'
SkeletalMesh=SkeletalMesh'CH_LIAM_Cathode.Mesh.SK_CH_LIAM_Cathode'
AnimTreeTemplate=AnimTree'CH_AnimHuman_Tree.AT_CH_Human'
PhysicsAsset=PhysicsAsset'CH_AnimCorrupt.Mesh.SK_CH_Corrupt_Male_Physics'
AnimSets(0)= AnimSet'CH_AnimHuman.Anims.K_AnimHuman_BaseMale'
Translation=(Z=8.0)
Scale=1.075
//General Mesh Properties
bCacheAnimSequenceNodes=FALSE
AlwaysLoadOnClient=true
AlwaysLoadOnServer=true
bOwnerNoSee=false
CastShadow=true
BlockRigidBody=TRUE
bUpdateSkelWhenNotRendered=false
bIgnoreControllersWhenNotRendered=TRUE
bUpdateKinematicBonesFromAnimation=true
bCastDynamicShadow=true
RBChannel=RBCC_Untitled3
RBCollideWithChannels=(Untitled3=true)
// LightEnvironment=MyLightEnvironment
bOverrideAttachmentOwnerVisibility=true
bAcceptsDynamicDecals=FALSE
bHasPhysicsAssetInstance=true
TickGroup=TG_PreAsyncWork
MinDistFactorForKinematicUpdate=0.2
bChartDistanceFactor=true
RBDominanceGroup=20
bUseOnePassLightingOnTranslucency=TRUE
bPerBoneMotionBlur=true
End Object
Mesh=WPawnSkeletalMeshComponent
Components.Add(WPawnSkeletalMeshComponent)
MyMeshComponent=WPawnSkeletalMeshComponent
Begin Object Name=CollisionCylinder
CollisionRadius=+0021.000000
CollisionHeight=+0044.000000
End Object
CylinderComponent=CollisionCylinder
}
CthulhuPlayerController.uc :
class CthulhuPlayerController extends GamePlayerController;
defaultproperties
{
CameraClass=class'CthulhuProject.CthulhuPlayerCamera'
}
CthulhuPlayerCamera.uc :
class CthulhuPlayerCamera extends Camera;
var Vector CamOffset;
var float CameraZOffset;
var float CameraScale, CurrentCameraScale; /** multiplier to default camera distance */
var float CameraScaleMin, CameraScaleMax;
function UpdateViewTarget(out TViewTarget OutVT, float DeltaTime)
{
local vector HitLocation, HitNormal;
local CameraActor CamActor;
local Pawn TPawn;
local vector CamStart, CamDirX, CamDirY, CamDirZ, CurrentCamOffset;
local float DesiredCameraZOffset;
// Don't update outgoing viewtarget during an interpolation
if( PendingViewTarget.Target != None && OutVT == ViewTarget && BlendParams.bLockOutgoing )
{
return;
}
// Default FOV on viewtarget
OutVT.POV.FOV = DefaultFOV;
// Viewing through a camera actor.
CamActor = CameraActor(OutVT.Target);
if( CamActor != None )
{
CamActor.GetCameraView(DeltaTime, OutVT.POV);
// Grab aspect ratio from the CameraActor.
bConstrainAspectRatio = bConstrainAspectRatio || CamActor.bConstrainAspectRatio;
OutVT.AspectRatio = CamActor.AspectRatio;
// See if the CameraActor wants to override the PostProcess settings used.
CamOverridePostProcessAlpha = CamActor.CamOverridePostProcessAlpha;
CamPostProcessSettings = CamActor.CamOverridePostProcess;
}
else
{
TPawn = Pawn(OutVT.Target);
// Give Pawn Viewtarget a chance to dictate the camera position.
// If Pawn doesn't override the camera view, then we proceed with our own defaults
if( TPawn == None || !TPawn.CalcCamera(DeltaTime, OutVT.POV.Location, OutVT.POV.Rotation, OutVT.POV.FOV) )
{
/**************************************
* Calculate third-person perspective
* Borrowed from UTPawn implementation
**************************************/
OutVT.POV.Rotation = PCOwner.Rotation;
CamStart = TPawn.Location;
CurrentCamOffset = CamOffset;
DesiredCameraZOffset = 1.2 * TPawn.GetCollisionHeight() + TPawn.Mesh.Translation.Z;
CameraZOffset = (DeltaTime < 0.2) ? DesiredCameraZOffset * 5 * DeltaTime + (1 - 5*DeltaTime) * CameraZOffset : DesiredCameraZOffset;
CamStart.Z += CameraZOffset;
GetAxes(OutVT.POV.Rotation, CamDirX, CamDirY, CamDirZ);
CamDirX *= CurrentCameraScale;
TPawn.FindSpot(Tpawn.GetCollisionExtent(),CamStart);
if (CurrentCameraScale < CameraScale)
{
CurrentCameraScale = FMin(CameraScale, CurrentCameraScale + 5 * FMax(CameraScale - CurrentCameraScale, 0.3)*DeltaTime);
}
else if (CurrentCameraScale > CameraScale)
{
CurrentCameraScale = FMax(CameraScale, CurrentCameraScale - 5 * FMax(CameraScale - CurrentCameraScale, 0.3)*DeltaTime);
}
if (CamDirX.Z > TPawn.GetCollisionHeight())
{
CamDirX *= square(cos(OutVT.POV.Rotation.Pitch * 0.0000958738)); // 0.0000958738 = 2*PI/65536
}
OutVT.POV.Location = CamStart - CamDirX*CurrentCamOffset.X + CurrentCamOffset.Y*CamDirY + CurrentCamOffset.Z*CamDirZ;
if (Trace(HitLocation, HitNormal, OutVT.POV.Location, CamStart, false, vect(12,12,12)) != None)
{
OutVT.POV.Location = HitLocation;
}
}
}
// Apply camera modifiers at the end (view shakes for example)
ApplyCameraModifiers(DeltaTime, OutVT.POV);
}
defaultproperties
{
CamOffset=(X=20.0,Y=50,Z=40)
CurrentCameraScale=1.0
CameraScale=9.0
CameraScaleMin=3.0
CameraScaleMax=40.0
}
This code is actually giving me the possibility of moving my pawn exactly as I want, but when I look up the character is not looking up ...
Thanks in advance
Replies
Do i need to assign the aimnode inside the code ? does anyone have an idea how to achieve it ?
Thanks