PDA

View Full Version : Custom camera - Weapon mesh invisible



zcarter
10-13-2010, 03:10 PM
Hello all and thank you for taking your time to read my post.

I am relatively new to unrealscript but I have been programming in C++ and other OOP languages for some time now.

Following the CameraTechnicalGuide article, I was able to implement a custom camera module in my custom game type. I also wrote a custom pawn, and player controller to do so.

Currently I have two different camera modes implemented, a side scrolling camera mode and a top down camera mode.

My problem is that, when I switch to one of these camera modes my weapon's mesh is no longer visible. I have also tried writing my own weapon class with a weapon attachment class as well and I still have no luck.

Currently I am trying to spawn the human controlled character with a shock rifle. I can fire the shock rifle and see the particle effects, but I see no weapon mesh. I'm guessing I'm just missing a call in my pawn class which sets the weapon attachment class correctly.

Anyway I've posted my code below, if anyone could help me I would greatly appreciate it. Thanks!

GameInfo Class -

class HostileAD extends GameInfo;

/** Default inventory added via AddDefaultInventory() */
var array< class<Inventory> > DefaultInventory;

var bool bGivePhysicsGun;

/** If true, look for nearby weaponlocker weapons */
var bool bStartWithLockerWeaps;

function AddDefaultInventory( pawn PlayerPawn )
{
local int i;

// may give the physics gun to non-bots
if( bGivePhysicsGun && PlayerPawn.IsHumanControlled() )
{
PlayerPawn.CreateInventory(class'UTWeap_PhysicsGun ',true);
}

for (i=0; i<DefaultInventory.Length; i++)
{
// Ensure we don't give duplicate items
if (PlayerPawn.FindInventoryType( DefaultInventory[i] ) == None)
{
// Only activate the first weapon
PlayerPawn.CreateInventory(DefaultInventory[i], (i > 0));
}
}

PlayerPawn.AddDefaultInventory();
}

DefaultProperties
{
bDelayedStart=false
bGivePhysicsGun=true
DefaultPawnClass=class'Hostile.HostilePawn'
PlayerControllerClass=class'Hostile.HostilePlayerC ontroller'
DefaultInventory(0)=class'UTWeap_ShockRifle'
}

Pawn Class -

class HostilePawn extends UTPawn;

/* Become View Target
* Called by Camera when this actor becomes its ViewTarget */
simulated event BecomeViewTarget(PlayerController PC)
{
local HostilePlayerController HPC;

HPC = HostilePlayerController(PC);

// Pawn is controlled by a HostilePlayerController and has a HostilePlayerCamera
if (HPC != none && HostilePlayerCamera(HPC.PlayerCamera) != none)
{
// Allow custom camera to control mesh visibility, etc...
HostilePlayerCamera(HPC.PlayerCamera).BecomeViewTa rget(HPC);
}
else
{
super.BecomeViewTarget(PC);
}
}

/**
* Calculate camera view point, when viewing this pawn
*
* @param fDeltaTime Delta time seconds since last update
* @param out_CamLoc Camera Location
* @param out_CamRot Camera Rotation
* @param out_FOV Field of View
*
* @return true if Pawn should provide the camera point of view.
*/
simulated function bool CalcCamera(float fDeltaTime, out vector out_CamLoc, out rotator out_CamRot, out float out_FOV )
{
// Return false to allow custom camera to control its location and rotation
return false;
}

/**
* Returns Base Aim Rotation without any adjustment (no aim error, no autolock, no adhesion...
* just clean initial aim rotation!)
*
* @return Base Aim Rotation
*/
simulated singular event Rotator GetBaseAimRotation()
{
local vector POVLoc;
local Rotator POVRot;
local HostilePlayerController PC;

PC = HostilePlayerController(Controller);

// Pawn is controlled by a HostilePlayerController and has a HostilePlayerCamera
if (PC != none && PC.ControlModule != none)
{
// Allow custom camera to control aim rotation
return PC.ControlModule.GetBaseAimRotation();
}
else
{
if (Controller != none && !InFreeCam() )
{
Controller.GetPlayerViewPoint(POVLoc, POVRot);
return POVRot;
}
else
{
POVRot = Rotation;

if( POVRot.Pitch == 0 )
{
POVRot.Pitch = RemoteViewPitch << 8;
}

return POVRot;
}
}
}

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_C H_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);
}


PlayerController Class -

class HostilePlayerController extends UTPlayerController;

// Player control module to use
var HostileControlModule ControlModule;
// Default class for player control module
var config string DefaultControlModuleClass;

// Exec function for switching to a different camera by class
exec function ChangeControls( string ClassName )
{
local class<HostileControlModule> ControlClass;
local HostileControlModule NewControlModule;

ControlClass = class<HostileControlModule>( DynamicLoadObject ( DefaultControlModuleClass, class'Class' ) );

if (ControlClass != none)
{
// Associate module with PlayerController
NewControlModule = new(Outer) ControlClass;
NewControlModule.Controller = self;
NewControlModule.Init();

// Call active / inactive functions on new / old modules
if (ControlModule != none)
{
ControlModule.OnBecomeInactive(NewControlModule);
NewControlModule.OnBecomeActive(ControlModule);
}
else
{
NewControlModule.OnBecomeActive(None);
}

ControlModule = NewControlModule;
}
else
{
`Log("Couldn't get control module class!");
// Not having a Control Class is fine. PlayerController will use default controls.
}
}

// Exec function for switching to a different camera by class
exec function ChangeCamera( string ClassName )
{
local class<HostilecameraModule> NewClass;

NewClass = class<HostileCameraModule>( DynamicLoadObject ( ClassName, class'Class' ) );

if (NewClass != none && HostilePlayerCamera(PlayerCamera) != none)
{
HostilePlayerCamera(PlayerCamera).CreateCamera(New Class);
}
}

// Zoom in exec
exec function ZoomIn()
{
if (HostilePlayerCamera(PlayerCamera) != none)
{
HostilePlayerCamera(PlayerCamera).ZoomIn();
}
}

// Zoom out exec
exec function ZoomOut()
{
if (HostilePlayerCamera(PlayerCamera) != none)
{
HostilePlayerCamera(PlayerCamera).ZoomOut();
}
}

simulated function PostBeginPlay()
{
local class<HostileControlModule> ControlClass;
local HostileControlModule NewControlModule;

super.PostBeginPlay();

ControlClass = class<HostileControlModule>( DynamicLoadObject( DefaultControlModuleClass, class'Class' ) );

if (ControlClass != none)
{
// Associate module with player controller
NewControlModule = new(Outer) ControlClass;
NewControlModule.Controller = self;
NewControlModule.Init();

// Call active / inactive functions on new / old modules
if (ControlModule != none)
{
ControlModule.OnBecomeInactive(NewControlModule);
ControlModule.OnBecomeActive(ControlModule);
}
else
{
ControlModule.OnBecomeActive(none);
}

ControlModule = NewControlModule;
}
else
{
`log("Couldn't get control module class!");
// Not having a Control Class is fine. PlayerController will use default controls.
}
}

state PlayerWalking
{
function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
{
// Controller has a HostilePlayerCamera
if (ControlModule != none)
{
ControlModule.ProcessMove(DeltaTime, NewAccel, DoubleClickMove, DeltaRot);
}
else
{
super.ProcessMove(DeltaTime, NewAccel, DoubleClickMove, DeltaRot);
}
}
}

function UpdateRotation(float DeltaTime)
{
// Controller has a HostilePlayerCamera
if(ControlModule != none)
{
// Allow custom control module to update our rotation
ControlModule.UpdateRotation(DeltaTime);
}
else
{
Super.UpdateRotation(DeltaTime);
}
}

/* GetPlayerViewPoint: Returns Player's Point of View
* For the AI this means the Pawn's Eyes ViewPoint
* For a human player, this means the Camera's ViewPoint */
simulated event GetPlayerViewPoint( out vector POVLocation, out Rotator POVRotation)
{
local float DeltaTime;
local UTPawn P;

P = IsLocalPlayerController() ? UTPawn(CalcViewActor) : none;

if (LastCameraTimeStamp == WorldInfo.TimeSeconds
&& CalcViewActor == ViewTarget
&& CalcViewActor != none
&& CalcViewActor.Location == CalcViewActorLocation
&& CalcViewActor.Rotation == CalcViewActorRotation
)
{
if ( (P == none) || ((P.EyeHeight == CalcEyeHeight) && (P.WalkBob == CalcWalkBob)) )
{
// Use cached result
POVLocation = CalcViewLocation;
POVRotation = CalcViewRotation;
return;
}
}

DeltaTime = WorldInfo.TimeSeconds - LastCameraTimeStamp;
LastCameraTimeStamp = WorldInfo.TimeSeconds;

// Support for using CameraActor views
if (CameraActor(ViewTarget) != none)
{
if (PlayerCamera == none)
{
super.ResetCameraMode();
SpawnCamera();
}
super.GetPlayerViewPoint( POVLocation, POVRotation);
}
else
{
// Do not destroy our camera!!
/* if ( PlayerCamera != None )
{
PlayerCamera.Destroy();
PlayerCamera = None;
} */

// No camera, we have view target - let view target be in control
if (PlayerCamera == none && ViewTarget != none)
{
POVRotation = Rotation;
if ( (PlayerReplicationInfo != none) && PlayerReplicationInfo.bOnlySpectator && (UTVehicle(ViewTarget) != none) )
{
UTVehicle(ViewTarget).bSpectatedView = true;
ViewTarget.CalcCamera(DeltaTime, POVLocation, POVRotation, FOVAngle);
UTVehicle(ViewTarget).bSpectatedView = false;
}
else
{
ViewTarget.CalcCamera(DeltaTime, POVLocation, POVRotation, FOVAngle);
}

if (bFreeCamera)
{
POVRotation = Rotation;
}
}
// No camera, no view target - wea re in control
else if (PlayerCamera == none)
{
CalcCamera(DeltaTime, POVLocation, POVRotation, FOVAngle);
return;
}
// We have a camera - let camera be in control
else
{
POVLocation = PlayerCamera.ViewTarget.POV.Location;
POVRotation = PlayerCamera.ViewTarget.POV.Rotation;
FOVAngle = PlayerCamera.ViewTarget.POV.FOV;
}
}

// Apply view shake
POVRotation = Normalize(POVRotation + ShakeRot);
POVLocation += ShakeOffset >> Rotation;

if (CameraEffect != none)
{
CameraEffect.UpdateLocation(POVLocation, POVRotation, GetFOVAngle());
}

// Cache result
CalcViewActor = ViewTarget;
CalcViewActorLocation = ViewTarget.Location;
CalcViewActorRotation = ViewTarget.Rotation;
CalcViewLocation = POVLocation;
CalcViewRotation = POVRotation;

if (P != none)
{
CalcEyeHeight = P.EyeHeight;
CalcWalkBob = P.WalkBob;
}
}

DefaultProperties
{
CameraClass=class'Hostile.HostilePlayerCamera'
MatineeCameraClass=class'Hostile.HostilePlayerCame ra'
}


I can post the camera code as well if that one help anyone diagnose my issue, or if they'd simply like to see the code, but it is straight out of the CameraTechnicalGuide so I don't see much point.

Thank you for reading!

zcarter
10-13-2010, 04:01 PM
Also,

I gave the fix geodav reccomended a try. I added this under the default properties of my attachment class - Rotation=(Yaw=16384) - but to no avail.

I was still unable to see the weapon mesh after making that change.

zcarter
10-13-2010, 08:43 PM
Anyone? I'm really scratching my head on this one...

Sorry for being new, but I've taken the initiative to do all the reading I could up to this point but now I'm stuck and could use some help from one of you experts out there.

I've tried going through the pawn class and moving anything dealing with weapon attachments into my pawn extension class.

The thing is, I'm not even trying to give my pawn a custom weapon, I'm just trying to use UTWeap_ShockRifle and it won't show up. The pawn definitely has the weapon, and I can fire it, but the attachment doesn't seem to be being applied correctly.

Thanks again for reading.

JohnGamer
10-14-2010, 03:06 AM
You can attach inside your weapon class the weapon with AttachWeaponTo function as mine:
simulated function AttachWeaponTo( SkeletalMeshComponent MeshCpnt, optional Name SocketName )
{

local HTPawn HTP;
HTP = HTPawn(Instigator);

super.AttachWeaponTo(MeshCpnt, SocketName);
//fscommand.cyclecamera();
PrintScreenDebug("Attaching Weapon");
// Attach 1st Person Muzzle Flashes, etc,
if ( Instigator.IsFirstPerson() )
{
AttachComponent(Mesh);
EnsureWeaponOverlayComponentLast();
SetHidden(false);
Mesh.SetLightEnvironment(HTP.LightEnvironment);
PrintScreenDebug("First Person Weapon Attached");
// HTPawn(Instigator).Cyclecamer();
}
else
{
SetHidden(true);
if (HTP != None)
{
Mesh.SetLightEnvironment(HTP.LightEnvironment); //share the light environment
Mesh.SetShadowParent(HTP.Mesh);//and the shadows
//SetBase(HTP,,HTP.Mesh,WeaponAttachmentSocketName); //base our actor on the pawn
HTP.Mesh.AttachComponentToSocket(Mesh,SocketName); //and attach our skeletalmesh component to our pawn's socket
`Log("Socket exists");
}
}
}

zcarter
10-14-2010, 03:36 AM
Thanks, and I've given that a shot already.

Let me try and explain my problem more clearly -

I have written a custom game which extends from game info. The code can be seen in the OP.

I also wrote custom classes for my pawn, playercontroller, and topdown / sidescrolling camera modules based off of the Camera Technical Guide provided by the UDK.

The issue I'm facing is that after extending from GameInfo, UTPawn and UTPlayerController, and after implementing a custom camera module based off of the camera technical guide, I am unable to see my character's weapon mesh when in a custom camera view.

I'm guessing my pawn class is missing an override somewhere but I can't see it.

Thanks for your suggestion though

zcarter
10-14-2010, 11:09 AM
Still trying to figure this one out if anyone has any ideas.

JohnGamer
10-14-2010, 02:48 PM
Did you set weapon socket for pawn mesh to attach your weapon to it for example 'WeaponSocket'.
If you did that you should use my last function to show your weapon in its hand.
That may help you.