LuckyRobotsUnreal/Source/Luckyrobots/TP_VehicleAdvOffroadCar.cpp

85 lines
4.1 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "TP_VehicleAdvOffroadCar.h"
#include "TP_VehicleAdvOffroadWheelFront.h"
#include "TP_VehicleAdvOffroadWheelRear.h"
#include "ChaosWheeledVehicleMovementComponent.h"
#include "GameFramework/SpringArmComponent.h"
ATP_VehicleAdvOffroadCar::ATP_VehicleAdvOffroadCar()
{
// construct the mesh components
Chassis = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Chassis"));
Chassis->SetupAttachment(GetMesh());
// NOTE: tire sockets are set from the Blueprint class
TireFrontLeft = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Tire Front Left"));
TireFrontLeft->SetupAttachment(GetMesh(), FName("VisWheel_FL"));
TireFrontLeft->SetCollisionProfileName(FName("NoCollision"));
TireFrontRight = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Tire Front Right"));
TireFrontRight->SetupAttachment(GetMesh(), FName("VisWheel_FR"));
TireFrontRight->SetCollisionProfileName(FName("NoCollision"));
TireFrontRight->SetRelativeRotation(FRotator(0.0f, 180.0f, 0.0f));
TireRearLeft = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Tire Rear Left"));
TireRearLeft->SetupAttachment(GetMesh(), FName("VisWheel_BL"));
TireRearLeft->SetCollisionProfileName(FName("NoCollision"));
TireRearRight = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Tire Rear Right"));
TireRearRight->SetupAttachment(GetMesh(), FName("VisWheel_BR"));
TireRearRight->SetCollisionProfileName(FName("NoCollision"));
TireRearRight->SetRelativeRotation(FRotator(0.0f, 180.0f, 0.0f));
// adjust the cameras
GetFrontSpringArm()->SetRelativeLocation(FVector(-5.0f, -30.0f, 135.0f));
GetBackSpringArm()->SetRelativeLocation(FVector(0.0f, 0.0f, 75.0f));
// Note: for faster iteration times, the vehicle setup can be tweaked in the Blueprint instead
// Set up the chassis
GetChaosVehicleMovement()->ChassisHeight = 160.0f;
GetChaosVehicleMovement()->DragCoefficient = 0.1f;
GetChaosVehicleMovement()->DownforceCoefficient = 0.1f;
GetChaosVehicleMovement()->CenterOfMassOverride = FVector(0.0f, 0.0f, 75.0f);
GetChaosVehicleMovement()->bEnableCenterOfMassOverride = true;
// Set up the wheels
GetChaosVehicleMovement()->bLegacyWheelFrictionPosition = true;
GetChaosVehicleMovement()->WheelSetups.SetNum(4);
GetChaosVehicleMovement()->WheelSetups[0].WheelClass = UTP_VehicleAdvOffroadWheelFront::StaticClass();
GetChaosVehicleMovement()->WheelSetups[0].BoneName = FName("PhysWheel_FL");
GetChaosVehicleMovement()->WheelSetups[0].AdditionalOffset = FVector(0.0f, 0.0f, 0.0f);
GetChaosVehicleMovement()->WheelSetups[1].WheelClass = UTP_VehicleAdvOffroadWheelFront::StaticClass();
GetChaosVehicleMovement()->WheelSetups[1].BoneName = FName("PhysWheel_FR");
GetChaosVehicleMovement()->WheelSetups[1].AdditionalOffset = FVector(0.0f, 0.0f, 0.0f);
GetChaosVehicleMovement()->WheelSetups[2].WheelClass = UTP_VehicleAdvOffroadWheelRear::StaticClass();
GetChaosVehicleMovement()->WheelSetups[2].BoneName = FName("PhysWheel_BL");
GetChaosVehicleMovement()->WheelSetups[2].AdditionalOffset = FVector(0.0f, 0.0f, 0.0f);
GetChaosVehicleMovement()->WheelSetups[3].WheelClass = UTP_VehicleAdvOffroadWheelRear::StaticClass();
GetChaosVehicleMovement()->WheelSetups[3].BoneName = FName("PhysWheel_BR");
GetChaosVehicleMovement()->WheelSetups[3].AdditionalOffset = FVector(0.0f, 0.0f, 0.0f);
// Set up the engine
// NOTE: Check the Blueprint asset for the Torque Curve
GetChaosVehicleMovement()->EngineSetup.MaxTorque = 600.0f;
GetChaosVehicleMovement()->EngineSetup.MaxRPM = 5000.0f;
GetChaosVehicleMovement()->EngineSetup.EngineIdleRPM = 1200.0f;
GetChaosVehicleMovement()->EngineSetup.EngineBrakeEffect = 0.05f;
GetChaosVehicleMovement()->EngineSetup.EngineRevUpMOI = 5.0f;
GetChaosVehicleMovement()->EngineSetup.EngineRevDownRate = 600.0f;
// Set up the differential
GetChaosVehicleMovement()->DifferentialSetup.DifferentialType = EVehicleDifferential::AllWheelDrive;
GetChaosVehicleMovement()->DifferentialSetup.FrontRearSplit = 0.5f;
// Set up the steering
// NOTE: Check the Blueprint asset for the Steering Curve
GetChaosVehicleMovement()->SteeringSetup.SteeringType = ESteeringType::AngleRatio;
GetChaosVehicleMovement()->SteeringSetup.AngleRatio = 0.7f;
}