CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
Unreal
CarlaUnreal
Plugins
Carla
Source
Carla
Vehicle
MovementComponents
BaseCarlaMovementComponent.cpp
Go to the documentation of this file.
1
// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2
// de Barcelona (UAB).
3
// Copyright (c) 2019 Intel Corporation
4
//
5
// This work is licensed under the terms of the MIT license.
6
// For a copy, see <https://opensource.org/licenses/MIT>.
7
8
#include "
BaseCarlaMovementComponent.h
"
9
#include "
Carla/Vehicle/CarlaWheeledVehicle.h
"
10
11
#include <
util/disable-ue4-macros.h
>
12
#include <
carla/Logging.h
>
13
#include <
util/enable-ue4-macros.h
>
14
15
16
void
UBaseCarlaMovementComponent::BeginPlay
()
17
{
18
Super::BeginPlay();
19
ACarlaWheeledVehicle
*
Vehicle
= Cast<ACarlaWheeledVehicle>(GetOwner());
20
if
(
Vehicle
)
21
{
22
CarlaVehicle
=
Vehicle
;
23
}
24
else
25
{
26
UE_LOG(LogCarla, Warning, TEXT(
"Error: Owner is not properly set for UBaseCarlaMovementComponent"
) );
27
}
28
}
29
30
void
UBaseCarlaMovementComponent::ProcessControl
(
FVehicleControl
&Control)
31
{
32
33
}
34
35
FVector
UBaseCarlaMovementComponent::GetVelocity
()
const
36
{
37
if
(
CarlaVehicle
)
38
{
39
return
CarlaVehicle
->AWheeledVehiclePawn::GetVelocity();
40
}
41
return
FVector();
42
}
43
44
int32
UBaseCarlaMovementComponent::GetVehicleCurrentGear
()
const
45
{
46
return
0;
47
}
48
49
float
UBaseCarlaMovementComponent::GetVehicleForwardSpeed
()
const
50
{
51
return
0.f;
52
}
53
54
void
UBaseCarlaMovementComponent::DisableUE4VehiclePhysics
()
55
{
56
if
(!
CarlaVehicle
)
57
{
58
UE_LOG(LogCarla, Warning, TEXT(
"Error: Owner is not properly set for UCarSimManagerComponent"
) );
59
return
;
60
}
61
CarlaVehicle
->GetVehicleMovementComponent()->SetComponentTickEnabled(
false
);
62
CarlaVehicle
->GetVehicleMovementComponent()->Deactivate();
63
CarlaVehicle
->GetMesh()->PhysicsTransformUpdateMode = EPhysicsTransformUpdateMode::ComponentTransformIsKinematic;
64
auto
* Bone =
CarlaVehicle
->GetMesh()->GetBodyInstance(NAME_None);
65
if
(Bone)
66
{
67
Bone->SetInstanceSimulatePhysics(
false
);
68
}
69
}
70
71
void
UBaseCarlaMovementComponent::EnableUE4VehiclePhysics
(
bool
bResetVelocity)
72
{
73
74
FVector CurrentVelocity(0, 0, 0);
75
if
(!bResetVelocity)
76
{
77
CurrentVelocity =
GetVelocity
();
78
}
79
CarlaVehicle
->GetMesh()->SetPhysicsLinearVelocity(CurrentVelocity,
false
,
"Vehicle_Base"
);
80
CarlaVehicle
->GetVehicleMovementComponent()->SetComponentTickEnabled(
true
);
81
CarlaVehicle
->GetVehicleMovementComponent()->Activate();
82
CarlaVehicle
->GetMesh()->PhysicsTransformUpdateMode = EPhysicsTransformUpdateMode::SimulationUpatesComponentTransform;
83
auto
* Bone =
CarlaVehicle
->GetMesh()->GetBodyInstance(NAME_None);
84
if
(Bone)
85
{
86
Bone->SetInstanceSimulatePhysics(
true
);
87
}
88
else
89
{
90
carla::log_warning(
"No bone with name"
);
91
}
92
CarlaVehicle
->GetMesh()->SetCollisionResponseToChannel(ECollisionChannel::ECC_WorldStatic, ECollisionResponse::ECR_Block);
93
CarlaVehicle
->GetMesh()->SetCollisionProfileName(
"Vehicle"
);
94
CarlaVehicle
->
RestoreVehiclePhysicsControl
();
95
}
BaseCarlaMovementComponent.h
CarlaWheeledVehicle.h
Logging.h
Vehicle
@ Vehicle
Definition
Unreal/CarlaUnreal/Plugins/Carla/Source/Carla/Util/EnvironmentObject.h:21
ACarlaWheeledVehicle
Base class for CARLA wheeled vehicles.
Definition
CarlaWheeledVehicle.h:85
ACarlaWheeledVehicle::RestoreVehiclePhysicsControl
void RestoreVehiclePhysicsControl()
Definition
CarlaWheeledVehicle.cpp:944
UBaseCarlaMovementComponent::ProcessControl
virtual void ProcessControl(FVehicleControl &Control)
Definition
BaseCarlaMovementComponent.cpp:30
UBaseCarlaMovementComponent::BeginPlay
virtual void BeginPlay() override
Definition
BaseCarlaMovementComponent.cpp:16
UBaseCarlaMovementComponent::GetVehicleCurrentGear
virtual int32 GetVehicleCurrentGear() const
Definition
BaseCarlaMovementComponent.cpp:44
UBaseCarlaMovementComponent::GetVehicleForwardSpeed
virtual float GetVehicleForwardSpeed() const
Definition
BaseCarlaMovementComponent.cpp:49
UBaseCarlaMovementComponent::EnableUE4VehiclePhysics
void EnableUE4VehiclePhysics(bool bResetVelocity=true)
Definition
BaseCarlaMovementComponent.cpp:71
UBaseCarlaMovementComponent::GetVelocity
virtual FVector GetVelocity() const
Definition
BaseCarlaMovementComponent.cpp:35
UBaseCarlaMovementComponent::CarlaVehicle
ACarlaWheeledVehicle * CarlaVehicle
Definition
BaseCarlaMovementComponent.h:28
UBaseCarlaMovementComponent::DisableUE4VehiclePhysics
void DisableUE4VehiclePhysics()
Definition
BaseCarlaMovementComponent.cpp:54
disable-ue4-macros.h
enable-ue4-macros.h
FVehicleControl
Definition
Unreal/CarlaUnreal/Plugins/Carla/Source/Carla/Vehicle/VehicleControl.h:13
Generated by
1.18.0