Advertisement
Benjiko99

CarGamePawn.cpp

Jun 8th, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.82 KB | None | 0 0
  1. // Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
  2.  
  3. #include "CarGame.h"
  4. #include "CarGamePawn.h"
  5. #include "CarGameWheelFront.h"
  6. #include "CarGameWheelRear.h"
  7.  
  8. float TurnValue;
  9.  
  10.  
  11. ACarGamePawn::ACarGamePawn(const class FPostConstructInitializeProperties& PCIP)
  12.     : Super(PCIP)
  13. {
  14.     // [Car mesh]
  15.     static ConstructorHelpers::FObjectFinder<USkeletalMesh> CarMesh(TEXT("/Game/Vehicle/SK_MyCar.SK_MyCar"));
  16.     Mesh->SetSkeletalMesh(CarMesh.Object);
  17.  
  18.     static ConstructorHelpers::FObjectFinder<UClass> AnimBPClass(TEXT("/Game/Vehicle/MyCar_AnimBP.MyCar_AnimBP_C"));
  19.     Mesh->SetAnimClass(AnimBPClass.Object);
  20.  
  21.     // [Simulation]
  22.     UWheeledVehicleMovementComponent4W* Vehicle4W = CastChecked<UWheeledVehicleMovementComponent4W>(VehicleMovement);
  23.  
  24.     check(Vehicle4W->WheelSetups.Num() == 4);
  25.  
  26.     Vehicle4W->WheelSetups[0].WheelClass = UCarGameWheelFront::StaticClass();
  27.     Vehicle4W->WheelSetups[0].BoneName = FName("Tire_frontleft");
  28.     Vehicle4W->WheelSetups[0].AdditionalOffset = FVector(0.f, -12.f, 0.f);
  29.  
  30.     Vehicle4W->WheelSetups[1].WheelClass = UCarGameWheelFront::StaticClass();
  31.     Vehicle4W->WheelSetups[1].BoneName = FName("Tire_frontright");
  32.     Vehicle4W->WheelSetups[1].AdditionalOffset = FVector(0.f, 12.f, 0.f);
  33.  
  34.     Vehicle4W->WheelSetups[2].WheelClass = UCarGameWheelRear::StaticClass();
  35.     Vehicle4W->WheelSetups[2].BoneName = FName("Tire_rearleft");
  36.     Vehicle4W->WheelSetups[2].AdditionalOffset = FVector(0.f, -12.f, 0.f);
  37.  
  38.     Vehicle4W->WheelSetups[3].WheelClass = UCarGameWheelRear::StaticClass();
  39.     Vehicle4W->WheelSetups[3].BoneName = FName("Tire_rearright");
  40.     Vehicle4W->WheelSetups[3].AdditionalOffset = FVector(0.f, 12.f, 0.f);
  41.  
  42.     // [Create a spring arm component]
  43.     SpringArm = PCIP.CreateDefaultSubobject<USpringArmComponent>(this, TEXT("SpringArm0"));
  44.     SpringArm->TargetOffset = FVector(0.f, 0.f, 200.f);
  45.     SpringArm->SetRelativeRotation(FRotator(-15.f, 0.f, 0.f));
  46.     SpringArm->AttachTo(RootComponent);
  47.     SpringArm->TargetArmLength = 600.0f;
  48.     SpringArm->bEnableCameraRotationLag = true;
  49.     SpringArm->CameraRotationLagSpeed = 7.f;
  50.     SpringArm->bInheritPitch = false;
  51.     SpringArm->bInheritRoll = false;
  52.  
  53.     // [Create camera component]
  54.     Camera = PCIP.CreateDefaultSubobject<UCameraComponent>(this, TEXT("Camera0"));
  55.     Camera->AttachTo(SpringArm, USpringArmComponent::SocketName);
  56.     Camera->bUseControllerViewRotation = false;
  57.     Camera->FieldOfView = 90.f;
  58.  
  59.     // [Vehicle setup]
  60.     using namespace EVehicleDifferential4W;
  61.     //static ConstructorHelpers::FObjectFinder<FRuntimeFloatCurve> TorqueCurve(TEXT("/Game/Vehicle/C_MyCar_Torque.C_MyCar_Torque"));
  62.     //Vehicle4W->EngineSetup.TorqueCurve = TorqueCurve.Object; // Acceleration
  63.  
  64.     Vehicle4W->DifferentialSetup.DifferentialType = Open_FrontDrive;
  65.     Vehicle4W->EngineSetup.MaxRPM = 6000.f; // Top Speed
  66. }
  67.  
  68.  
  69. void ACarGamePawn::SetupPlayerInputComponent(class UInputComponent* InputComponent)
  70. {
  71.     // set up gameplay key bindings
  72.     check(InputComponent);
  73.  
  74.     InputComponent->BindAxis("Vertical", this, &ACarGamePawn::MoveVertical);
  75.     InputComponent->BindAxis("Horizontal", this, &ACarGamePawn::MoveHorizontal);
  76.  
  77.     InputComponent->BindAction("Handbrake", IE_Pressed, this, &ACarGamePawn::OnHandbrakePressed);
  78.     InputComponent->BindAction("Handbrake", IE_Released, this, &ACarGamePawn::OnHandbrakeReleased);
  79. }
  80.  
  81.  
  82. void ACarGamePawn::MoveVertical(float Val)
  83. {
  84.     GetVehicleMovementComponent()->SetThrottleInput(Val);
  85. }
  86.  
  87.  
  88. void ACarGamePawn::MoveHorizontal(float Val)
  89. {
  90.     TurnValue = Val;
  91.     GetVehicleMovementComponent()->SetSteeringInput(TurnValue); // Remove if you get the tick to work
  92. }
  93.  
  94.  
  95. void ACarGamePawn::OnHandbrakePressed()
  96. {
  97.     GetVehicleMovementComponent()->SetHandbrakeInput(true);
  98. }
  99.  
  100.  
  101. void ACarGamePawn::OnHandbrakeReleased()
  102. {
  103.     GetVehicleMovementComponent()->SetHandbrakeInput(false);
  104. }
  105.  
  106.  
  107. //void ACarGamePawn::Tick(0.f)
  108. //{
  109. //  GetVehicleMovementComponent()->SetSteeringInput(TurnValue);
  110. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement