CARLA
 
载入中...
搜索中...
未找到
VehicleVelocityControl.cpp
浏览该文件的文档.
1// Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#include "Kismet/KismetMathLibrary.h"
8
10
11
12UVehicleVelocityControl::UVehicleVelocityControl()
13{
14 PrimaryComponentTick.bCanEverTick = true;
15}
16
17void UVehicleVelocityControl::BeginPlay()
18{
19 Super::BeginPlay();
20
21 SetComponentTickEnabled(false);
22 SetTickGroup(ETickingGroup::TG_PrePhysics);
23
24 OwnerVehicle = GetOwner();
25 PrimitiveComponent = Cast<UPrimitiveComponent>(OwnerVehicle->GetRootComponent());
26}
27
28void UVehicleVelocityControl::Activate(bool bReset)
29{
30 Super::Activate(bReset);
31
32 TargetVelocity = FVector();
33 SetComponentTickEnabled(true);
34}
35
36void UVehicleVelocityControl::Activate(FVector Velocity, bool bReset)
37{
38 Super::Activate(bReset);
39
40 TargetVelocity = Velocity;
41 SetComponentTickEnabled(true);
42}
43
44void UVehicleVelocityControl::Deactivate()
45{
46 SetComponentTickEnabled(false);
47 Super::Deactivate();
48}
49
50void UVehicleVelocityControl::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
51{
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");
56}