ある球体を自分の周りに仰角、方位角方向に15度刻みでテレポーテーションさせるアクタを作っています
方位角方向には360度きれいに回ってくれるのですが、
仰角方向に関しては135度付近で進んだり戻ったりを繰り返してしまいます。
どうかご助力お願いします。
挙動部分のプログラムは以下のようにコンポーネントを使用しております。
<.cpp>
#include "SoundLocation.h"
#include "Engine/World.h"
#include "Engine/Engine.h"
// Sets default values
ASoundLocation::ASoundLocation(const class FObjectInitializer& PCIP) : Super(PCIP)
{
// 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;
AActor *actor = GetOwner();
Scene = PCIP.CreateDefaultSubobject<USceneComponent>(this, TEXT("SLBaseScene"));
Scene->SetRelativeLocation(RelativeLocation);
Scene->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
SphereComponent = PCIP.CreateDefaultSubobject<USphereComponent>(this, TEXT("RootComponent"));
RootComponent = SphereComponent;
SphereComponent->InitSphereRadius(40.0f);
SphereComponent->SetCollisionProfileName(TEXT("Pawn"));
SphereVisual = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("VisualRepresentation"));
SphereVisual->SetupAttachment(RootComponent);
static ConstructorHelpers::FObjectFinder<UStaticMesh> SphereVisualAsset(TEXT("/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere"));
if (SphereVisualAsset.Succeeded())
{
SphereVisual->SetStaticMesh(SphereVisualAsset.Object);
SphereVisual->SetRelativeLocation(FVector(320.0f, 0.0f, 110.0f));
SphereVisual->SetWorldScale3D(FVector(0.8f));
}
}
// Called when the game starts or when spawned
void ASoundLocation::BeginPlay()
{
Super::BeginPlay();
APlayerController* PlayerController = Cast<APlayerController>(GetWorld()->GetFirstPlayerController()->GetPawn()->GetController());
if (PlayerController) {
EnableInput(PlayerController);
InputComponent->BindAction("Transfar_Y", IE_Pressed, this, &ASoundLocation::ObjectTransportation_y);
InputComponent->BindAction("Transfar_P", IE_Pressed, this, &ASoundLocation::ObjectTransportation_p);
}
}
void ASoundLocation::ObjectTransportation_y()
{
FRotator NewRot = GetActorRotation();
NewRot.Yaw = NewRot.Yaw+15;
SetActorRotation(NewRot);
}
void ASoundLocation::ObjectTransportation_p()
{
FRotator NewRot = GetActorRotation();
NewRot.Pitch = NewRot.Pitch + 15;
SetActorRotation(NewRot);
}
以上、よろしくです