Followed this tutorial: Make a Vehicle with C++ in Unreal Engine 4 - YouTube
I followed all the blueprints and triple checked all my naming for my inputs in the editor, once I press play my vehicle just floats in the air, I can look around, but not move the car itself. I am using a different vehicle, could it be that?
Header and cpp:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include <OtherProjectWouldNot/GunnerProjectile.h>
#include "CoreMinimal.h"
#include "WheeledVehicle.h"
#include "MyWheeledVehicle.generated.h"
/**
*
*/
class UGunnerProjectile;
UCLASS()
class OTHERPROJECTWOULDNOT_API AMyWheeledVehicle : public AWheeledVehicle
{
GENERATED_BODY()
AMyWheeledVehicle();
virtual void Tick(float Deltatime) override;
virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override;
void TurnLeft(float direction);
void TurnForward(float Direction);
void ThrottleInput(float Input);
void SteerInput(float Input);
void OnPressedHandBrake();
void OnReleasedHandBrake(float DeltaTime);
void Fire();
UPROPERTY(VisibleAnywhere, Category = "Camera")
class UCameraComponent* Camera;
UPROPERTY(VisibleAnywhere, Category = "SpringArm")
class USpringArmComponent* SpringArm;
UPROPERTY(EditDefaultsOnly, Category = "Projectile Class")
TSubclassOf<AGunnerProjectile> GunnerProjectileClass;
UPROPERTY(EditAnywhere, Category = "GunMuzzle")
USkeletalMeshComponent* Gun;
UPROPERTY(VisibleDefaultsOnly, Category = Mesh)
USkeletalMeshComponent* Mesh1P;
UPROPERTY(EditAnywhere, Category = "GunMuzzle")
USceneComponent* MuzzleLocation;
UPROPERTY(EditAnywhere, Category = "GunOffset ")
FVector GunOffset;
void UpdateInAirControl(float Deltatime);
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyWheeledVehicle.h"
#include "WheeledVehicleMovementComponent4W.h"
#include "Components/SkeletalMeshComponent.h"
#include "Components/InputComponent.h"
#include "GameframeWork/SpringArmComponent.h"
#include "Camera/CameraComponent.h"
static const FName NAME_SteerInput("MoveRight");
static const FName NAME_ThrottleInput("MoveForward");
AMyWheeledVehicle::AMyWheeledVehicle()
{
UWheeledVehicleMovementComponent4W* Vehicle4W = CastChecked<UWheeledVehicleMovementComponent4W>(GetVehicleMovement());
/** Clamp normalized tire load to these values */
Vehicle4W->MinNormalizedTireLoad = 0.0f;
Vehicle4W->MaxNormalizedTireLoadFiltered = 2.0f;
Vehicle4W->MaxNormalizedTireLoad = 2.0f;
Vehicle4W->MinNormalizedTireLoadFiltered = 0.0f;
Vehicle4W->MaxEngineRPM = 6000;
Vehicle4W->EngineSetup.TorqueCurve.GetRichCurve()->Reset();
Vehicle4W->EngineSetup.TorqueCurve.GetRichCurve()->AddKey(0.0f,400.0f);
Vehicle4W->EngineSetup.TorqueCurve.GetRichCurve()->AddKey(1900.0f,500.0f);
Vehicle4W->EngineSetup.TorqueCurve.GetRichCurve()->AddKey(6000.0f,400.0f);
Vehicle4W->SteeringCurve.GetRichCurve()->Reset();
Vehicle4W->SteeringCurve.GetRichCurve()->AddKey(0.0f, 1.0f);
Vehicle4W->SteeringCurve.GetRichCurve()->AddKey(40.0f, 0.7f);
Vehicle4W->SteeringCurve.GetRichCurve()->AddKey(120.0f, 0.6f);
//changing turning rates for the back wheels
Vehicle4W->DifferentialSetup.DifferentialType = EVehicleDifferential4W::LimitedSlip_4W;
Vehicle4W->DifferentialSetup.FrontRearSplit = 0.50;
Gun = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Gun"));
Gun->SetupAttachment(Mesh1P, TEXT("gun_jnt"));
Gun->SetupAttachment(RootComponent);
MuzzleLocation = CreateDefaultSubobject<USceneComponent>(TEXT("Muzzle Location"));
MuzzleLocation->SetupAttachment(Gun);
MuzzleLocation->SetRelativeLocation(FVector(63.0f, 86.0f, 10.0f));
Vehicle4W->TransmissionSetup.bUseGearAutoBox = true;
Vehicle4W->TransmissionSetup.GearSwitchTime = 1.0f;
Vehicle4W->TransmissionSetup.GearAutoBoxLatency = 0.75f;
SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArm"));
SpringArm->SetupAttachment(RootComponent);
SpringArm->TargetArmLength = 250.0f;
SpringArm->bUsePawnControlRotation = true;
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera Babby"));
Camera->FieldOfView = 120.0f;
Camera->SetupAttachment(SpringArm, USpringArmComponent::SocketName);
//GunOffset = FVector(63.0f, 86.0f, 10.0f);
}
void AMyWheeledVehicle::Tick(float Deltatime)
{
Super::Tick(Deltatime);
UpdateInAirControl(Deltatime);
}
void AMyWheeledVehicle::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAction("Brakes", IE_Pressed, this, &AMyWheeledVehicle::OnPressedHandBrake);
PlayerInputComponent->BindAction("Brakes", IE_Released, this, &AMyWheeledVehicle::OnPressedHandBrake);
PlayerInputComponent->BindAxis("Turn",this, &AMyWheeledVehicle::TurnLeft);
PlayerInputComponent->BindAxis("LookUp",this,&AMyWheeledVehicle::TurnForward);
PlayerInputComponent->BindAxis(NAME_ThrottleInput,this,&AMyWheeledVehicle::ThrottleInput);
PlayerInputComponent->BindAxis(NAME_SteerInput,this,&AMyWheeledVehicle::SteerInput);
PlayerInputComponent->BindAction("Shoot", IE_Pressed, this, &AMyWheeledVehicle::Fire);
}
void AMyWheeledVehicle::TurnLeft(float direction)
{
if(direction != 0.0f)
{
AddControllerPitchInput(direction);
}
}
void AMyWheeledVehicle::TurnForward(float Direction)
{
if (Direction != 0.0f)
{
AddControllerYawInput(Direction);
}
}
void AMyWheeledVehicle::ThrottleInput(float Input)
{
GetVehicleMovementComponent()->SetThrottleInput(Input);
}
void AMyWheeledVehicle::SteerInput(float Input)
{
GetVehicleMovementComponent()->SetSteeringInput(Input);
}
void AMyWheeledVehicle::OnPressedHandBrake()
{
GetVehicleMovementComponent()->SetHandbrakeInput(true);
}
void AMyWheeledVehicle::OnReleasedHandBrake(float DeltaTime)
{
GetVehicleMovementComponent()->SetHandbrakeInput(true);
}
void AMyWheeledVehicle::Fire()
{
FHitResult Hit;
float WeaponRange = 200.0f;
FCollisionQueryParams QueryParams = FCollisionQueryParams(SCENE_QUERY_STAT(WeaponRange), false, this);
UWorld* World = GetWorld();
if (GunnerProjectileClass != nullptr)
{
if (GetWorld() != nullptr)
{
const FRotator Rotator = GetControlRotation();
const FVector SpawnLocation = MuzzleLocation->GetComponentLocation();
FActorSpawnParameters ActorSpawnParams;
ActorSpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButDontSpawnIfColliding;
AGunnerProjectile* Projectile = World->SpawnActor<AGunnerProjectile>(GunnerProjectileClass, SpawnLocation, Rotator , ActorSpawnParams);
}
}
}
void AMyWheeledVehicle::UpdateInAirControl(float Deltatime)
{
if (UWheeledVehicleMovementComponent4W* Vehicle4W = CastChecked<UWheeledVehicleMovementComponent4W>(GetVehicleMovement()))
{
}
}