From e5014e29f9b62cc2517766f71e7567fe9520fa1d Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Thu, 2 Jun 2016 17:13:00 +0200 Subject: [PATCH] Add function to disable collision for InstanceObjects --- rwengine/include/objects/InstanceObject.hpp | 2 ++ rwengine/src/objects/InstanceObject.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/rwengine/include/objects/InstanceObject.hpp b/rwengine/include/objects/InstanceObject.hpp index 7b1d9b98..450d5e44 100644 --- a/rwengine/include/objects/InstanceObject.hpp +++ b/rwengine/include/objects/InstanceObject.hpp @@ -38,6 +38,8 @@ public: virtual bool takeDamage(const DamageInfo& damage); + void setSolid(bool solid); + float getHealth() const { return health; } }; diff --git a/rwengine/src/objects/InstanceObject.cpp b/rwengine/src/objects/InstanceObject.cpp index 0663c07d..1eb99796 100644 --- a/rwengine/src/objects/InstanceObject.cpp +++ b/rwengine/src/objects/InstanceObject.cpp @@ -174,4 +174,20 @@ bool InstanceObject::takeDamage(const GameObject::DamageInfo& dmg) return false; } +void InstanceObject::setSolid(bool solid) +{ + // Early out in case we don't have a collision body + if (body == nullptr || body->body == nullptr) { + return; + } + + int flags = body->body->getCollisionFlags(); + if (solid) { + flags &= ~btCollisionObject::CF_NO_CONTACT_RESPONSE; + } else { + flags |= btCollisionObject::CF_NO_CONTACT_RESPONSE; + } + body->body->setCollisionFlags(flags); +} +