7#include "Kismet/KismetMathLibrary.h"
12UVehicleVelocityControl::UVehicleVelocityControl()
14 PrimaryComponentTick.bCanEverTick =
true;
17void UVehicleVelocityControl::BeginPlay()
21 SetComponentTickEnabled(
false);
22 SetTickGroup(ETickingGroup::TG_PrePhysics);
24 OwnerVehicle = GetOwner();
25 PrimitiveComponent = Cast<UPrimitiveComponent>(OwnerVehicle->GetRootComponent());
28void UVehicleVelocityControl::Activate(
bool bReset)
30 Super::Activate(bReset);
32 TargetVelocity = FVector();
33 SetComponentTickEnabled(
true);
36void UVehicleVelocityControl::Activate(FVector Velocity,
bool bReset)
38 Super::Activate(bReset);
40 TargetVelocity = Velocity;
41 SetComponentTickEnabled(
true);
44void UVehicleVelocityControl::Deactivate()
46 SetComponentTickEnabled(
false);
50void UVehicleVelocityControl::TickComponent(
float DeltaTime,
enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
52 TRACE_CPUPROFILER_EVENT_SCOPE(UVehicleVelocityControl::TickComponent);
53 FTransform Transf = OwnerVehicle->GetActorTransform();
54 const FVector LocVel = Transf.TransformVector(TargetVelocity);
55 PrimitiveComponent->SetPhysicsLinearVelocity(LocVel,
false,
"None");