feat(physics): added CanCollide property (which still fires Touched)
This commit is contained in:
parent
c1c088118b
commit
8c6f038b9f
3 changed files with 25 additions and 0 deletions
|
@ -70,6 +70,7 @@ public:
|
|||
|
||||
DEF_PROP_CATEGORY(BEHAVIOR)
|
||||
DEF_PROP_(on_update=onUpdated) bool anchored = false;
|
||||
DEF_PROP_(on_update=onUpdated) bool canCollide = true;
|
||||
DEF_PROP bool locked = false;
|
||||
|
||||
DEF_PROP_CATEGORY(SURFACE)
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "physics/util.h"
|
||||
#include <memory>
|
||||
#include <reactphysics3d/collision/CollisionCallback.h>
|
||||
#include <reactphysics3d/collision/OverlapCallback.h>
|
||||
#include <reactphysics3d/engine/PhysicsCommon.h>
|
||||
|
||||
rp::PhysicsCommon* Workspace::physicsCommon = new rp::PhysicsCommon;
|
||||
|
@ -42,6 +43,25 @@ void PhysicsEventListener::onContact(const rp::CollisionCallback::CallbackData&
|
|||
}
|
||||
}
|
||||
|
||||
void PhysicsEventListener::onTrigger(const rp::OverlapCallback::CallbackData& data) {
|
||||
for (size_t i = 0; i < data.getNbOverlappingPairs(); i++) {
|
||||
auto pair = data.getOverlappingPair(i);
|
||||
auto type = pair.getEventType();
|
||||
if (type == rp::OverlapCallback::OverlapPair::EventType::OverlapStay) continue;
|
||||
|
||||
auto part0 = reinterpret_cast<Part*>(pair.getBody1()->getUserData())->shared<Part>();
|
||||
auto part1 = reinterpret_cast<Part*>(pair.getBody2()->getUserData())->shared<Part>();
|
||||
|
||||
if (type == reactphysics3d::OverlapCallback::OverlapPair::EventType::OverlapStart) {
|
||||
part0->Touched->Fire({ (Variant)InstanceRef(part1) });
|
||||
part1->Touched->Fire({ (Variant)InstanceRef(part0) });
|
||||
} else if (type == reactphysics3d::OverlapCallback::OverlapPair::EventType::OverlapExit) {
|
||||
part0->TouchEnded->Fire({ (Variant)InstanceRef(part1) });
|
||||
part1->TouchEnded->Fire({ (Variant)InstanceRef(part0) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Workspace::InitService() {
|
||||
if (initialized) return;
|
||||
initialized = true;
|
||||
|
@ -107,6 +127,9 @@ void Workspace::SyncPartPhysics(std::shared_ptr<Part> part) {
|
|||
part->rigidBody->setType(part->anchored ? rp::BodyType::STATIC : rp::BodyType::DYNAMIC);
|
||||
part->rigidBody->getCollider(0)->setCollisionCategoryBits(0b11);
|
||||
|
||||
part->rigidBody->getCollider(0)->setIsSimulationCollider(part->canCollide);
|
||||
part->rigidBody->getCollider(0)->setIsTrigger(!part->canCollide);
|
||||
|
||||
rp::Material& material = part->rigidBody->getCollider(0)->getMaterial();
|
||||
material.setFrictionCoefficient(0.35);
|
||||
material.setMassDensity(1.f);
|
||||
|
|
|
@ -44,6 +44,7 @@ class PhysicsEventListener : public rp::EventListener {
|
|||
PhysicsEventListener(Workspace*);
|
||||
|
||||
void onContact(const rp::CollisionCallback::CallbackData&) override;
|
||||
void onTrigger(const rp::OverlapCallback::CallbackData&) override;
|
||||
};
|
||||
|
||||
class DEF_INST_SERVICE_(explorer_icon="workspace") Workspace : public Service {
|
||||
|
|
Loading…
Add table
Reference in a new issue