-
I built out a quick aircraft class using c++ and created a blueprint from it. I added the Vigilante F16 model and got the structural origin lined up pretty much perfect. I have inputs set up for everything. The problem I have is when I give it throttle, everything works exactly as it should, but the plane is moving backwards. I can even take off and fly, but it's like the model is turned 180 degrees. Here's what my Aircraft.h and Aircraft.cpp files look like, but I suspect my problem is in the blueprint somewhere: Aircraft.h: // Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "Aircraft.generated.h"
UCLASS()
class AAircraft : public APawn
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, Category = "Aircraft")
class USkeletalMeshComponent* SkeletalMesh;
UPROPERTY(EditAnywhere, Category = "Aircraft")
class USpringArmComponent* ChaseCameraBoom;
UPROPERTY(EditAnywhere, Category = "Aircraft")
class UCameraComponent* ChaseCamera;
UPROPERTY(EditAnywhere, Category = "Aircraft")
class UJSBSimMovementComponent* Movement;
void ThrottleUp();
void ThrottleDown();
void AileronInput(float Value);
void ElevatorInput(float Value);
void RudderInput(float Value);
public:
AAircraft();
protected:
virtual void BeginPlay() override;
public:
virtual void Tick(float DeltaTime) override;
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
UFUNCTION(BlueprintCallable)
UJSBSimMovementComponent* GetMovement();
}; Aircraft.cpp: // Fill out your copyright notice in the Description page of Project Settings.
#include "Vehicles/Aircraft/Aircraft.h"
#include "Aircraft.h"
#include "Components/SkeletalMeshComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h"
#include "JSBSimMovementComponent.h"
AAircraft::AAircraft()
{
PrimaryActorTick.bCanEverTick = true;
this->SkeletalMesh = this->CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("SkeletalMesh"));
this->SkeletalMesh->SetupAttachment(this->GetRootComponent());
this->ChaseCameraBoom = this->CreateDefaultSubobject<USpringArmComponent>(TEXT("ChaseCameraBoom"));
this->ChaseCameraBoom->SetupAttachment(this->SkeletalMesh);
this->ChaseCamera = this->CreateDefaultSubobject<UCameraComponent>(TEXT("ChaseCamera"));
this->ChaseCamera->SetupAttachment(this->ChaseCameraBoom);
this->Movement = this->CreateDefaultSubobject<UJSBSimMovementComponent>(TEXT("Movement"));
}
void AAircraft::BeginPlay()
{
Super::BeginPlay();
}
void AAircraft::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AAircraft::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAction("ThrottleUp", IE_Pressed, this, &AAircraft::ThrottleUp);
PlayerInputComponent->BindAction("ThrottleDown", IE_Pressed, this, &AAircraft::ThrottleDown);
PlayerInputComponent->BindAxis("Pitch", this, &AAircraft::ElevatorInput);
PlayerInputComponent->BindAxis("Roll", this, &AAircraft::AileronInput);
PlayerInputComponent->BindAxis("Yaw", this, &AAircraft::RudderInput);
}
void AAircraft::ThrottleUp()
{
for (int i = 0; i < this->Movement->EngineCommands.Num(); i++)
{
if (this->Movement->EngineCommands[i].Throttle < 1.0f)
this->Movement->EngineCommands[i].Throttle += .05f;
}
}
void AAircraft::ThrottleDown()
{
for (int i = 0; i < this->Movement->EngineCommands.Num(); i++)
{
if (this->Movement->EngineCommands[i].Throttle > 0.0f)
this->Movement->EngineCommands[i].Throttle -= .05f;
}
}
void AAircraft::RudderInput(float Value)
{
this->Movement->Commands.Rudder = Value;
}
void AAircraft::ElevatorInput(float Value)
{
this->Movement->Commands.Elevator = Value;
}
void AAircraft::AileronInput(float Value)
{
this->Movement->Commands.Aileron = Value;
}
UJSBSimMovementComponent* AAircraft::GetMovement()
{
return this->Movement;
} |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Yes there was some bug between JSBSim/UE5 plugin that caused a reversed velocity under certain conditions. Unfortunately I don't remember what conditions triggered it and haven't had it happen in awhile to remember what to do to stop it. Try changing various initial conditions in the level editor, like starts on ground, air speed, position, etc. And try using a different flight model. |
Beta Was this translation helpful? Give feedback.
-
We’ll, it’s resolved itself today, but I have no idea why. At some point I created a new level because I was having some issues with my terrain. Maybe that fixed it. |
Beta Was this translation helpful? Give feedback.
-
I just re-encountered this bug and found out it's happening from the GeoReference Component. When changing from Round planet to Flat planet, the Flat planet causes the aircraft to be reversed. Will investigate later. |
Beta Was this translation helpful? Give feedback.
We’ll, it’s resolved itself today, but I have no idea why. At some point I created a new level because I was having some issues with my terrain. Maybe that fixed it.