7 #include "Kismet/KismetMathLibrary.h" 12 UVehicleVelocityControl::UVehicleVelocityControl()
14 PrimaryComponentTick.bCanEverTick =
true;
17 void UVehicleVelocityControl::BeginPlay()
21 SetComponentTickEnabled(
false);
22 SetTickGroup(ETickingGroup::TG_PrePhysics);
24 OwnerVehicle = GetOwner();
25 PrimitiveComponent = Cast<UPrimitiveComponent>(OwnerVehicle->GetRootComponent());
28 void UVehicleVelocityControl::Activate(
bool bReset)
30 Super::Activate(bReset);
32 TargetVelocity = FVector();
33 SetComponentTickEnabled(
true);
36 void UVehicleVelocityControl::Activate(FVector Velocity,
bool bReset)
38 Super::Activate(bReset);
40 TargetVelocity = Velocity;
41 SetComponentTickEnabled(
true);
44 void UVehicleVelocityControl::Deactivate()
46 SetComponentTickEnabled(
false);
50 void 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");