From d832a190282cedfe4797f4e340a7c48b2c0cb6dd Mon Sep 17 00:00:00 2001 From: Manish Date: Thu, 18 Apr 2019 12:57:50 +0200 Subject: [PATCH] Friction Trigger volumes getting spawned with box extents + solved a bug --- .../Source/Carla/Trigger/FrictionTrigger.cpp | 8 +++---- .../Source/Carla/Trigger/FrictionTrigger.h | 5 +++++ .../Source/Carla/Trigger/TriggerFactory.cpp | 22 +++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Trigger/FrictionTrigger.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Trigger/FrictionTrigger.cpp index 50e7cbc9e..d233c916e 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Trigger/FrictionTrigger.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Trigger/FrictionTrigger.cpp @@ -43,8 +43,8 @@ void AFrictionTrigger::OnTriggerBeginOverlap( bool /*bFromSweep*/, const FHitResult & /*SweepResult*/) { - ACarlaWheeledVehicle *Vehicle = CastChecked(OtherActor); - if (Vehicle) + ACarlaWheeledVehicle *Vehicle = Cast(OtherActor); + if (Vehicle != nullptr) { TArray WheelsFrictionScale = Vehicle->GetWheelsFrictionScale(); for (auto &FrictionScale : WheelsFrictionScale) @@ -62,8 +62,8 @@ void AFrictionTrigger::OnTriggerEndOverlap( UPrimitiveComponent * /*OtherComp*/, int32 /*OtherBodyIndex*/) { - ACarlaWheeledVehicle *Vehicle = CastChecked(OtherActor); - if (Vehicle) + ACarlaWheeledVehicle *Vehicle = Cast(OtherActor); + if (Vehicle != nullptr) { TArray WheelsFrictionScale = Vehicle->GetWheelsFrictionScale(); for (auto &FrictionScale : WheelsFrictionScale) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Trigger/FrictionTrigger.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Trigger/FrictionTrigger.h index 8304cce67..0b31e1716 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Trigger/FrictionTrigger.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Trigger/FrictionTrigger.h @@ -43,6 +43,11 @@ public: Episode = &InEpisode; } + void SetBoxExtent(const FVector &Extent) + { + TriggerVolume->SetBoxExtent(Extent); + } + protected: virtual void BeginPlay() override; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Trigger/TriggerFactory.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Trigger/TriggerFactory.cpp index 7e45cb39a..05e1b04e2 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Trigger/TriggerFactory.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Trigger/TriggerFactory.cpp @@ -65,6 +65,28 @@ FActorSpawnResult ATriggerFactory::SpawnActor( auto *Episode = GameInstance->GetCarlaEpisode(); check(Episode != nullptr); Trigger->SetEpisode(*Episode); + + FVector Extent {100.0f, 100.0f, 100.0f}; + + auto *ExtentX = Description.Variations.Find("extent_x"); + if (ExtentX != nullptr) + { + Extent.X = std::atof(TCHAR_TO_UTF8(*ExtentX->Value)); + } + + auto *ExtentY = Description.Variations.Find("extent_y"); + if (ExtentY != nullptr) + { + Extent.Y = std::atof(TCHAR_TO_UTF8(*ExtentY->Value)); + } + + auto *ExtentZ = Description.Variations.Find("extent_z"); + if (ExtentZ != nullptr) + { + Extent.Z = std::atof(TCHAR_TO_UTF8(*ExtentZ->Value)); + } + + Trigger->SetBoxExtent(Extent); } UGameplayStatics::FinishSpawningActor(Trigger, Transform); return FActorSpawnResult{Trigger};