Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fill out your copyright notice in the Description page of Project Settings.
- #include "Ship.h"
- // Sets default values
- AShip::AShip()
- {
- // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
- PrimaryActorTick.bCanEverTick = true;
- // |||| Variable Initialization |||||
- Acceleration = 500.f;
- TurnSpeed = 500.f;
- MaxSpeed = 4000.f;
- MinSpeed = 500.f;
- CurrentForwardSpeed = 2000.f;
- }
- // Called when the game starts or when spawned
- void AShip::BeginPlay()
- {
- Super::BeginPlay();
- }
- // Called every frame
- void AShip::Tick(float DeltaTime)
- {
- const FVector LocalMove = FVector(CurrentForwardSpeed * DeltaTime, 0.f, 0.f);
- AddActorLocalOffset(LocalMove, true);
- FRotator deltaRotation(0, 0, 0);
- deltaRotation.Pitch = CurrentPitchSpeed * DeltaTime;
- deltaRotation.Yaw = CurrentYawSpeed * DeltaTime;
- deltaRotation.Roll = CurrentRollSpeed * DeltaTime;
- AddActorLocalRotation(deltaRotation);
- Super::Tick(DeltaTime);
- }
- void AShip::MoveRight(float Val)
- {
- float targetYaw = Val * TurnSpeed;
- CurrentYawSpeed = FMath::FInterpTo(CurrentYawSpeed, targetYaw, GetWorld()->GetDeltaSeconds(), 2.0f);
- GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("targetYaw: %f"), targetYaw));
- GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("currentYawSpeed: %f"), CurrentYawSpeed));
- bool isTurning = FMath::Abs(Val) > 0.2f;
- float targetRollSpeed = isTurning ? (CurrentYawSpeed * 0.5f) : (GetActorRotation().Roll * -2.0f);
- CurrentRollSpeed = FMath::FInterpTo(CurrentRollSpeed, targetRollSpeed, GetWorld()->GetDeltaSeconds(), 2.0f);
- }
- // Called to bind functionality to input
- void AShip::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
- {
- Super::SetupPlayerInputComponent(PlayerInputComponent);
- PlayerInputComponent->BindAxis("Right", this, &AShip::MoveRight);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement