Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
- #include "CarGame.h"
- #include "CarGamePawn.h"
- #include "CarGameWheelFront.h"
- #include "CarGameWheelRear.h"
- float TurnValue;
- ACarGamePawn::ACarGamePawn(const class FPostConstructInitializeProperties& PCIP)
- : Super(PCIP)
- {
- // [Car mesh]
- static ConstructorHelpers::FObjectFinder<USkeletalMesh> CarMesh(TEXT("/Game/Vehicle/SK_MyCar.SK_MyCar"));
- Mesh->SetSkeletalMesh(CarMesh.Object);
- static ConstructorHelpers::FObjectFinder<UClass> AnimBPClass(TEXT("/Game/Vehicle/MyCar_AnimBP.MyCar_AnimBP_C"));
- Mesh->SetAnimClass(AnimBPClass.Object);
- // [Simulation]
- UWheeledVehicleMovementComponent4W* Vehicle4W = CastChecked<UWheeledVehicleMovementComponent4W>(VehicleMovement);
- check(Vehicle4W->WheelSetups.Num() == 4);
- Vehicle4W->WheelSetups[0].WheelClass = UCarGameWheelFront::StaticClass();
- Vehicle4W->WheelSetups[0].BoneName = FName("Tire_frontleft");
- Vehicle4W->WheelSetups[0].AdditionalOffset = FVector(0.f, -12.f, 0.f);
- Vehicle4W->WheelSetups[1].WheelClass = UCarGameWheelFront::StaticClass();
- Vehicle4W->WheelSetups[1].BoneName = FName("Tire_frontright");
- Vehicle4W->WheelSetups[1].AdditionalOffset = FVector(0.f, 12.f, 0.f);
- Vehicle4W->WheelSetups[2].WheelClass = UCarGameWheelRear::StaticClass();
- Vehicle4W->WheelSetups[2].BoneName = FName("Tire_rearleft");
- Vehicle4W->WheelSetups[2].AdditionalOffset = FVector(0.f, -12.f, 0.f);
- Vehicle4W->WheelSetups[3].WheelClass = UCarGameWheelRear::StaticClass();
- Vehicle4W->WheelSetups[3].BoneName = FName("Tire_rearright");
- Vehicle4W->WheelSetups[3].AdditionalOffset = FVector(0.f, 12.f, 0.f);
- // [Create a spring arm component]
- SpringArm = PCIP.CreateDefaultSubobject<USpringArmComponent>(this, TEXT("SpringArm0"));
- SpringArm->TargetOffset = FVector(0.f, 0.f, 200.f);
- SpringArm->SetRelativeRotation(FRotator(-15.f, 0.f, 0.f));
- SpringArm->AttachTo(RootComponent);
- SpringArm->TargetArmLength = 600.0f;
- SpringArm->bEnableCameraRotationLag = true;
- SpringArm->CameraRotationLagSpeed = 7.f;
- SpringArm->bInheritPitch = false;
- SpringArm->bInheritRoll = false;
- // [Create camera component]
- Camera = PCIP.CreateDefaultSubobject<UCameraComponent>(this, TEXT("Camera0"));
- Camera->AttachTo(SpringArm, USpringArmComponent::SocketName);
- Camera->bUseControllerViewRotation = false;
- Camera->FieldOfView = 90.f;
- // [Vehicle setup]
- using namespace EVehicleDifferential4W;
- //static ConstructorHelpers::FObjectFinder<FRuntimeFloatCurve> TorqueCurve(TEXT("/Game/Vehicle/C_MyCar_Torque.C_MyCar_Torque"));
- //Vehicle4W->EngineSetup.TorqueCurve = TorqueCurve.Object; // Acceleration
- Vehicle4W->DifferentialSetup.DifferentialType = Open_FrontDrive;
- Vehicle4W->EngineSetup.MaxRPM = 6000.f; // Top Speed
- }
- void ACarGamePawn::SetupPlayerInputComponent(class UInputComponent* InputComponent)
- {
- // set up gameplay key bindings
- check(InputComponent);
- InputComponent->BindAxis("Vertical", this, &ACarGamePawn::MoveVertical);
- InputComponent->BindAxis("Horizontal", this, &ACarGamePawn::MoveHorizontal);
- InputComponent->BindAction("Handbrake", IE_Pressed, this, &ACarGamePawn::OnHandbrakePressed);
- InputComponent->BindAction("Handbrake", IE_Released, this, &ACarGamePawn::OnHandbrakeReleased);
- }
- void ACarGamePawn::MoveVertical(float Val)
- {
- GetVehicleMovementComponent()->SetThrottleInput(Val);
- }
- void ACarGamePawn::MoveHorizontal(float Val)
- {
- TurnValue = Val;
- GetVehicleMovementComponent()->SetSteeringInput(TurnValue); // Remove if you get the tick to work
- }
- void ACarGamePawn::OnHandbrakePressed()
- {
- GetVehicleMovementComponent()->SetHandbrakeInput(true);
- }
- void ACarGamePawn::OnHandbrakeReleased()
- {
- GetVehicleMovementComponent()->SetHandbrakeInput(false);
- }
- //void ACarGamePawn::Tick(0.f)
- //{
- // GetVehicleMovementComponent()->SetSteeringInput(TurnValue);
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement