Hello everybody,
i have some problems getting my character work. if i hit the play button im not able to move to body or even looking through the camera which is attached at the charakter. maybe i forget something, im confused right now maybe someone have an idea. here is my code.
Code
// Fill out your copyright notice in the Description page of Project Settings.
#include "PS4_v1.h"
#include "MMU.h"
#define print(text) if (GEngine) GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, text)
// Sets default values
AMMU::AMMU()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
//set the size of the capsule
GetCapsuleComponent()->SetCapsuleSize(50.f, 100.f);
//GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
GetCapsuleComponent()->SetSimulatePhysics(true);
GetCharacterMovement()->bOrientRotationToMovement = false; // do not move the direction we are looking
//setup the cameracomponent
m_uCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent"));
m_uCameraComponent->AttachParent = GetCapsuleComponent();
m_uCameraComponent->RelativeLocation = FVector(0.0f, 0.0f, 80.f);
m_uCameraComponent->bUsePawnControlRotation = true; //maybe this should be disabled when using vr
////setup the mesh
//m_uMeshMMU = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("MMUMesh"));
//m_uMeshMMU->SetOnlyOwnerSee(true); //visible for us
//m_uMeshMMU->AttachParent = m_uCameraComponent;
//set baserate
m_fBaseRate = 25.0f;
}
// Called when the game starts or when spawned
void AMMU::BeginPlay()
{
Super::BeginPlay();
FString fString;
fString.Append("MMU selected");
print(fString);
}
// Called every frame
void AMMU::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
// Called to bind functionality to input
void AMMU::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
Super::SetupPlayerInputComponent(InputComponent);
//check if the inputcomponents are initialized
check(InputComponent);
//read an delegate the input to a function
InputComponent->BindAxis("MoveForward", this, &AMMU::moveForward);
InputComponent->BindAxis("MoveRight", this, &AMMU::moveRight);
InputComponent->BindAxis("MoveUp", this, &AMMU::moveUp);
InputComponent->BindAxis("Turn", this, &AMMU::turnRight);
}
void AMMU::moveForward( float _value )
{
if (_value != 0)
{
FString fString;
fString.Append("Applying Impulse to the MMU to move in y-direction");
GetCapsuleComponent()->AddImpulse(GetActorForwardVector() * (200.0f*_value));
print(fString);
}
}
void AMMU::moveRight( float _value )
{
if (_value != 0)
{
FString fString;
fString.Append("Applying Impulse to the MMU to move in x-direction");
GetCapsuleComponent()->AddImpulse(GetActorRightVector() * (200.0f*_value));
print(fString);
}
}
void AMMU::moveUp( float _value )
{
FString fString;
fString.Append("Applying Impulse to the MMU in z-direction");
if (_value != 0)
{
GetCapsuleComponent()->AddImpulse(GetActorUpVector() * (200.f*_value));
print(fString);
}
}
void AMMU::turnRight( float _value )
{
UWorld *world = GetWorld();
check(world);
FString fString;
fString.Append("Turn the MMU");
if (_value != 0)
{
AddControllerYawInput(_value * m_fBaseRate * world->GetDeltaSeconds());
print(fString);
}
}
Header
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "GameFramework/Character.h"
#include "MMU.generated.h"
UCLASS()
class PS4_V1_API AMMU : public ACharacter
{
GENERATED_BODY()
// Pawn Mesh: this should represent the MMU
//UPROPERTY( EditAnywhere, Category = "Mesh" )
//class USkeletalMeshComponent* m_uMeshMMU;
//
//// Camera to the MMU
UPROPERTY( EditAnywhere, Category = "Mesh - Camera" )
UCameraComponent* m_uCameraComponent;
public:
// Sets default values for this character's properties
AMMU();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent( class UInputComponent* InputComponent ) override;
protected:
// move MMU Unit forward
void moveForward( float _value );
// move MMU Unit right
void moveRight( float _value );
//move MMU Unit up
void moveUp( float _value );
//turn the MMU Unit
void turnRight( float _value );
//set the turnrate
UPROPERTY(Editanywhere, Category = "Mesh")
float m_fBaseRate = 0.0f;
private:
};
thanks and greetings