I create a demo FPS C++ project from templates. I wrote my own character class based on the FPSDemoCharacter .It works except that the camera and its child (arms) mesh receive no pitch.When I fire I do see the projectiles fly up and down along the pitch axis but the camera and the arms mesh don’t move.
What can be the problem?
Here is my code:
// Fill out your copyright notice in the Description page of Project Settings.
#include "Tactical1.h"
#include " FPS_Character.h"
#include " FPS_Projectile.h"
#include "Engine.h"
FPS_Character:: FPS_Character(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
m_baseTurnRate=45.f;
m_baseLookUpRate = 45.f;
// set our turn rates for input
//setup default FPS cam:
m_firstPersonCameraComp = PCIP.CreateDefaultSubobject<UCameraComponent>(this, TEXT("DefaultFPSCam"));
m_firstPersonCameraComp->AttachParent = CapsuleComponent;
//position camera a bit above the eyesL
m_firstPersonCameraComp->RelativeLocation = FVector(0.0f, 0.0f, 50.0f + BaseEyeHeight);
m_firstPersonCameraComp->bUsePawnControlRotation = true;
//setup fps mesh:
m_firstPersonMesh = PCIP.CreateDefaultSubobject<USkeletalMeshComponent>(this, TEXT("FPS_MESH"));
m_firstPersonMesh->SetOnlyOwnerSee(true);
m_firstPersonMesh->AttachParent = m_firstPersonCameraComp;
m_firstPersonMesh->bCastDynamicShadow = false;
m_firstPersonMesh->CastShadow = false;
Mesh->SetOwnerNoSee(true);//
}
void FPS_Character::SetupPlayerInputComponent(class UInputComponent* inputComponent){
//axis:
inputComponent->BindAxis("MoveForward", this, & FPS_Character::MoveForward);
inputComponent->BindAxis("MoveRight", this, & FPS_Character::MoveRight);
inputComponent->BindAxis("Turn", this, &APawn::AddControllerYawInput);
inputComponent->BindAxis("TurnRate", this, & FPS_Character::TurnAtRate);
inputComponent->BindAxis("LookUp", this, &APawn::AddControllerPitchInput);
inputComponent->BindAxis("LookUpRate", this, & FPS_Character::LookUpAtRate);
//actions:
inputComponent->BindAction("Jump", IE_Pressed, this, & FPS_Character::OnStartJump);
inputComponent->BindAction("Jump", IE_Released, this, & FPS_Character::OnStopJump);
inputComponent->BindAction("Fire", IE_Pressed, this, & FPS_Character::OnFire);
}
void ATCT_ Character::MoveForward(float value){
if ( (value != 0.0f)){
AddMovementInput(GetActorForwardVector(), value);
}
}
void FPS_Character::MoveRight(float value){
if ( (value != 0.0f))
{
AddMovementInput(GetActorRightVector(), value);
}
}
void FPS_Character::OnStartJump()
{
bPressedJump = true;
}
void FPS_Character::OnStopJump()
{
bPressedJump = false;
}
void FPS_Character::TurnAtRate(float Rate)
{
AddControllerYawInput(Rate * m_baseTurnRate * GetWorld()->GetDeltaSeconds());
}
void FPS_Character::LookUpAtRate(float Rate)
{
AddControllerPitchInput(Rate * m_baseLookUpRate * GetWorld()->GetDeltaSeconds());
}