Fixed water body presence physics
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <OgreBullet.h>
|
||||
#include "GameData.h"
|
||||
#include "CharacterModule.h"
|
||||
#include "WaterModule.h"
|
||||
#include "Components.h"
|
||||
namespace ECS
|
||||
{
|
||||
@@ -191,7 +192,19 @@ CharacterModule::CharacterModule(flecs::world &ecs)
|
||||
bool is_on_floor = false;
|
||||
bool penetration = false;
|
||||
Ogre::Vector3 gravity(0, -9.8, 0);
|
||||
body.gvelocity += gravity * delta;
|
||||
if (e.has<InWater>()) {
|
||||
float full_subm = 2.0f;
|
||||
float current_subm = -Ogre::Math::Clamp(
|
||||
pos.y, -full_subm, 0.0f);
|
||||
float b = 9.0 * current_subm / full_subm;
|
||||
body.gvelocity +=
|
||||
(gravity + Ogre::Vector3(0, b, 0)) *
|
||||
delta;
|
||||
body.gvelocity.y = Ogre::Math::Clamp(
|
||||
body.gvelocity.y, -1.0f, 1.0f);
|
||||
std::cout << "InWater!!!!!!!\n";
|
||||
} else
|
||||
body.gvelocity += gravity * delta;
|
||||
velocity += body.gvelocity;
|
||||
Ogre::Vector3 rotMotion = velocity * delta;
|
||||
btVector3 currentPosition =
|
||||
@@ -293,9 +306,8 @@ CharacterModule::CharacterModule(flecs::world &ecs)
|
||||
inertia);
|
||||
}
|
||||
body.mGhostObject->setCollisionFlags(
|
||||
btCollisionObject::CF_KINEMATIC_OBJECT |
|
||||
btCollisionObject::
|
||||
CF_NO_CONTACT_RESPONSE);
|
||||
btCollisionObject::CF_KINEMATIC_OBJECT /*|
|
||||
btCollisionObject::CF_NO_CONTACT_RESPONSE */);
|
||||
body.mGhostObject->setActivationState(
|
||||
DISABLE_DEACTIVATION);
|
||||
eng.mWorld->attachCollisionObject(
|
||||
@@ -459,6 +471,48 @@ CharacterModule::CharacterModule(flecs::world &ecs)
|
||||
body.checkGround = false;
|
||||
}
|
||||
});
|
||||
ecs.system<const WaterBody, const CharacterBase, CharacterBody>(
|
||||
"CharacterWater1")
|
||||
.kind(flecs::OnUpdate)
|
||||
.with<Character>()
|
||||
.without<InWater>()
|
||||
.each([](flecs::entity e, const WaterBody &waterb,
|
||||
const CharacterBase &ch, CharacterBody &body) {
|
||||
if (waterb.mInWater.find(body.mGhostObject) !=
|
||||
waterb.mInWater.end() &&
|
||||
ch.mBodyNode->_getDerivedPosition().y < -0.05f) {
|
||||
e.add<InWater>();
|
||||
std::cout << "Big Splash\n";
|
||||
}
|
||||
#if 0
|
||||
if (waterb.mInWater.find(body.mGhostObject) ==
|
||||
waterb.mInWater.end())
|
||||
e.add<InWater>();
|
||||
std::cout << waterb.mInWater.size() << " InWater\n";
|
||||
#endif
|
||||
});
|
||||
ecs.system<const WaterBody, const CharacterBase, CharacterBody>(
|
||||
"CharacterWater2")
|
||||
.kind(flecs::OnUpdate)
|
||||
.with<Character>()
|
||||
.with<InWater>()
|
||||
.each([](flecs::entity e, const WaterBody &waterb,
|
||||
const CharacterBase &ch, CharacterBody &body) {
|
||||
if (waterb.mInWater.find(body.mGhostObject) ==
|
||||
waterb.mInWater.end() &&
|
||||
ch.mBodyNode->_getDerivedPosition().y > 0.05f)
|
||||
e.remove<InWater>();
|
||||
});
|
||||
ecs.system<const EngineData, CharacterBase, CharacterBody>(
|
||||
"DisplayPlayerPos")
|
||||
.kind(flecs::OnUpdate)
|
||||
.with<Character>()
|
||||
.with<Player>()
|
||||
.each([](const EngineData &eng, CharacterBase &ch,
|
||||
CharacterBody &body) {
|
||||
std::cout << "player: " << ch.mBodyNode->getPosition()
|
||||
<< "\n";
|
||||
});
|
||||
}
|
||||
|
||||
void CharacterModule::setAnimation(AnimationControl &anim)
|
||||
|
||||
Reference in New Issue
Block a user