7#include "Kismet/KismetMathLibrary.h"
12UVehicleVelocityControl::UVehicleVelocityControl()
15 PrimaryComponentTick.bCanEverTick =
true;
18void UVehicleVelocityControl::BeginPlay()
23 SetComponentTickEnabled(
false);
26 SetTickGroup(ETickingGroup::TG_PrePhysics);
29 OwnerVehicle = GetOwner();
31 PrimitiveComponent = Cast<UPrimitiveComponent>(OwnerVehicle->GetRootComponent());
35void UVehicleVelocityControl::Activate(
bool bReset)
37 Super::Activate(bReset);
40 TargetVelocity = FVector();
43 SetComponentTickEnabled(
true);
47void UVehicleVelocityControl::Activate(FVector Velocity,
bool bReset)
49 Super::Activate(bReset);
51 TargetVelocity = Velocity;
52 SetComponentTickEnabled(
true);
55void UVehicleVelocityControl::Deactivate()
57 SetComponentTickEnabled(
false);
61void UVehicleVelocityControl::TickComponent(
float DeltaTime,
enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
63 TRACE_CPUPROFILER_EVENT_SCOPE(UVehicleVelocityControl::TickComponent);
64 FTransform Transf = OwnerVehicle->GetActorTransform();
65 const FVector LocVel = Transf.TransformVector(TargetVelocity);
67 PrimitiveComponent->SetPhysicsLinearVelocity(LocVel,
false,
"None");