Hi guys, i am doing a first project, a simple Arkanoid:
My player(a brick) -> Pawn(sceneComponent,staticMeshComponent,CameraComponent: sceneComponent is Root, the rest are attached to Root)
The background where the “enemy” bricks will spawn (AActor : sceneComponent,StaticMeshComponent)
i spawn those classes completly in C++, NOTHING of blueprints(that is the idea). My player brick moves perfectly but the camera follow the “horizontal” movement of my Pawn. i Tried instead of moving with this->getActorLocation.Y , trying to move accesing directly the staticMesh
using this->myStaticMeshComponent->getlocation.Y , but this doesnt seems to work, nothing happens. Here some Code:
I Already searched the forum and used Google but other user´s cases doesnt seems to help in my case
“Tablero” is the backGround where the enemy bricks will spawn:
ATablero::ATablero()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
PrimaryActorTick.bCanEverTick = true;
OurVisibleComponent = CreateDefaultSubobject<USceneComponent>(TEXT(“Scenecomponent”));
tablero = CreateDefaultSubobject<UStaticMeshComponent>(TEXT(“Tablero”));
RootComponent=OurVisibleComponent;
tablero->AttachTo(RootComponent);
}
-----------------------------*------------------
AMyPawn::AMyPawn()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
PrimaryActorTick.bCanEverTick = true;
// Set this pawn to be controlled by the lowest-numbered player
AutoPossessPlayer = EAutoReceiveInput::Player0;
// Create a dummy root component we can attach things to.
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
// Create a camera and a visible object
OurCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("OurCamera"));
player = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("OurVisibleComponent"));
// Attach our camera and visible object to our root component. Offset and rotate the camera.
//OurCamera->AttachTo(RootComponent);
OurCamera->SetRelativeLocation(FVector(-250.0f, 0.0f,0.0f));
OurCamera->SetRelativeRotation(FRotator(0.0f, 0.0f, 0.0f));
player->AttachTo(RootComponent);
}
// Called when the game starts or when spawned
void AMyPawn::BeginPlay()
{
Super::BeginPlay();/*
APlayerController* OurPlayerController = UGameplayStatics::GetPlayerController(this, 0);
if (OurPlayerController != NULL){
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT(“This is an on screen message!”));
//OurPlayerController->SetViewTarget(OurCamera);
}
*/
}
// Called every frame
void AMyPawn::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
// Called to bind functionality to input
void AMyPawn::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
Super::SetupPlayerInputComponent(InputComponent);
InputComponent->BindAxis(“movimientoHorizontal”, this, &AMyPawn::movimiento); //movimientohorizontal means HorizontalMovement
}
void AMyPawn::movimiento(float value){ //movimiento means movement
if (value > 0){
//Like i said i tried using simply this->GetActorLocation() and following the same path but didnt worked.
FVector locationAux=player->RelativeLocation;
locationAux.Y = locationAux.Y + 250 * GetWorld()->DeltaTimeSeconds;
//FVector aux = this->GetActorLocation();
//aux.Y = aux.Y + 250 * GetWorld()->DeltaTimeSeconds;
//this->SetActorLocation(aux);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT(“%f”), locationAux.Y));
player->SetMobility(EComponentMobility::Movable);
player->RelativeLocation.Y = locationAux.Y;
//locationAux = player->RelativeLocation = locationAux;
}
}
-------------------------------**------------------------