diff --git a/Docs/python_api.md b/Docs/python_api.md index 5d2b39eff..0c3bba4d2 100644 --- a/Docs/python_api.md +++ b/Docs/python_api.md @@ -87,6 +87,7 @@ - `get_acceleration()` - `set_location(location)` - `set_transform(transform)` +- `set_simulate_physics(enabled=True)` - `destroy()` ## `carla.Vehicle(carla.Actor)` diff --git a/LibCarla/source/carla/client/Actor.cpp b/LibCarla/source/carla/client/Actor.cpp index 7dfcdc23a..323e31360 100644 --- a/LibCarla/source/carla/client/Actor.cpp +++ b/LibCarla/source/carla/client/Actor.cpp @@ -36,6 +36,10 @@ namespace client { GetEpisode().Lock()->SetActorTransform(*this, transform); } + void Actor::SetSimulatePhysics(const bool enabled) { + GetEpisode().Lock()->SetActorSimulatePhysics(*this, enabled); + } + void Actor::Destroy() { if (_is_alive) { // Let the exceptions leave the function, IsAlive() will still be true. diff --git a/LibCarla/source/carla/client/Actor.h b/LibCarla/source/carla/client/Actor.h index 8f5d673bb..ec26e3ef0 100644 --- a/LibCarla/source/carla/client/Actor.h +++ b/LibCarla/source/carla/client/Actor.h @@ -39,6 +39,8 @@ namespace client { void SetTransform(const geom::Transform &transform); + void SetSimulatePhysics(bool enabled = true); + const auto &Serialize() const { return Super::GetActorDescription(); } diff --git a/LibCarla/source/carla/client/detail/Client.cpp b/LibCarla/source/carla/client/detail/Client.cpp index 06448060e..f1415d0c1 100644 --- a/LibCarla/source/carla/client/detail/Client.cpp +++ b/LibCarla/source/carla/client/detail/Client.cpp @@ -126,6 +126,10 @@ namespace detail { _pimpl->AsyncCall("set_actor_transform", actor, transform); } + void Client::SetActorSimulatePhysics(const rpc::Actor &actor, const bool enabled) { + _pimpl->AsyncCall("set_actor_simulate_physics", actor, enabled); + } + void Client::SetActorAutopilot(const rpc::Actor &vehicle, const bool enabled) { _pimpl->AsyncCall("set_actor_autopilot", vehicle, enabled); } diff --git a/LibCarla/source/carla/client/detail/Client.h b/LibCarla/source/carla/client/detail/Client.h index 1d4e7f44f..4cfeaca02 100644 --- a/LibCarla/source/carla/client/detail/Client.h +++ b/LibCarla/source/carla/client/detail/Client.h @@ -86,6 +86,10 @@ namespace detail { const rpc::Actor &actor, const geom::Transform &transform); + void SetActorSimulatePhysics( + const rpc::Actor &actor, + bool enabled); + void SetActorAutopilot( const rpc::Actor &vehicle, bool enabled); diff --git a/LibCarla/source/carla/client/detail/Simulator.h b/LibCarla/source/carla/client/detail/Simulator.h index 4d72d7983..e4204b284 100644 --- a/LibCarla/source/carla/client/detail/Simulator.h +++ b/LibCarla/source/carla/client/detail/Simulator.h @@ -177,6 +177,10 @@ namespace detail { _client.SetActorTransform(actor.Serialize(), transform); } + void SetActorSimulatePhysics(Actor &actor, bool enabled) { + _client.SetActorSimulatePhysics(actor.Serialize(), enabled); + } + /// @} // ========================================================================= /// @name Operations with vehicles diff --git a/PythonAPI/source/libcarla/Actor.cpp b/PythonAPI/source/libcarla/Actor.cpp index 10ee0dd17..2a1c634c2 100644 --- a/PythonAPI/source/libcarla/Actor.cpp +++ b/PythonAPI/source/libcarla/Actor.cpp @@ -53,6 +53,7 @@ void export_actor() { .def("get_acceleration", &cc::Actor::GetAcceleration) .def("set_location", &cc::Actor::SetLocation, (arg("location"))) .def("set_transform", &cc::Actor::SetTransform, (arg("transform"))) + .def("set_simulate_physics", &cc::Actor::SetSimulatePhysics, (arg("enabled")=true)) .def("destroy", CALL_WITHOUT_GIL(cc::Actor, Destroy)) .def(self_ns::str(self_ns::self)) ; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/TheNewCarlaServer.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/TheNewCarlaServer.cpp index 08e6e4892..1abbacceb 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/TheNewCarlaServer.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/TheNewCarlaServer.cpp @@ -316,6 +316,19 @@ void FTheNewCarlaServer::FPimpl::BindActions() ETeleportType::TeleportPhysics); }); + Server.BindSync("set_actor_simulate_physics", [this](cr::Actor Actor, bool bEnabled) { + RequireEpisode(); + auto ActorView = Episode->GetActorRegistry().Find(Actor.id); + if (!ActorView.IsValid() || ActorView.GetActor()->IsPendingKill()) { + RespondErrorStr("unable to set actor simulate physics: actor not found"); + } + auto RootComponent = Cast<UPrimitiveComponent>(ActorView.GetActor()->GetRootComponent()); + if (RootComponent == nullptr) { + RespondErrorStr("unable to set actor simulate physics: not supported by actor"); + } + RootComponent->SetSimulatePhysics(bEnabled); + }); + Server.BindSync("apply_control_to_actor", [this](cr::Actor Actor, cr::VehicleControl Control) { RequireEpisode(); auto ActorView = Episode->GetActorRegistry().Find(Actor.id);