Function to disable simulating physics on an actor
This commit is contained in:
parent
994110047e
commit
c478eb039e
|
@ -87,6 +87,7 @@
|
|||
- `get_acceleration()`
|
||||
- `set_location(location)`
|
||||
- `set_transform(transform)`
|
||||
- `set_simulate_physics(enabled=True)`
|
||||
- `destroy()`
|
||||
|
||||
## `carla.Vehicle(carla.Actor)`
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -39,6 +39,8 @@ namespace client {
|
|||
|
||||
void SetTransform(const geom::Transform &transform);
|
||||
|
||||
void SetSimulatePhysics(bool enabled = true);
|
||||
|
||||
const auto &Serialize() const {
|
||||
return Super::GetActorDescription();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue