Merge pull request #193 from teamfisk/BoxModelCollision
Removed collision jittering effects
This commit is contained in:
@@ -19,6 +19,7 @@ public:
|
|||||||
virtual const glm::vec3 Rotation() const { return m_Rotation; }
|
virtual const glm::vec3 Rotation() const { return m_Rotation; }
|
||||||
virtual bool Jumping() const { return m_Jumping; }
|
virtual bool Jumping() const { return m_Jumping; }
|
||||||
virtual bool Crouching() const { return m_Crouching; }
|
virtual bool Crouching() const { return m_Crouching; }
|
||||||
|
virtual bool CrouchingLastFrame() const { return m_CrouchingLastFrame; }
|
||||||
virtual bool DoubleJumping() const { return m_DoubleJumping; }
|
virtual bool DoubleJumping() const { return m_DoubleJumping; }
|
||||||
virtual void SetDoubleJumping(bool isDoubleJumping) {
|
virtual void SetDoubleJumping(bool isDoubleJumping) {
|
||||||
m_DoubleJumping = isDoubleJumping;
|
m_DoubleJumping = isDoubleJumping;
|
||||||
@@ -44,6 +45,7 @@ protected:
|
|||||||
bool m_Jumping = false;
|
bool m_Jumping = false;
|
||||||
bool m_DoubleJumping = false;
|
bool m_DoubleJumping = false;
|
||||||
bool m_Crouching = false;
|
bool m_Crouching = false;
|
||||||
|
bool m_CrouchingLastFrame = false;
|
||||||
//assault dash membervariables - needed to calculate the doubletap- and dashlogic
|
//assault dash membervariables - needed to calculate the doubletap- and dashlogic
|
||||||
double m_AssaultDashDoubleTapDeltaTime = 0.0;
|
double m_AssaultDashDoubleTapDeltaTime = 0.0;
|
||||||
//i will let m_AssaultDashDoubleTapSensitivityTimer stay hardcoded, its not really a gamevariable (more an inputvariable),
|
//i will let m_AssaultDashDoubleTapSensitivityTimer stay hardcoded, its not really a gamevariable (more an inputvariable),
|
||||||
@@ -82,6 +84,7 @@ void FirstPersonInputController<EventContext>::Reset()
|
|||||||
{
|
{
|
||||||
m_Rotation = glm::vec3(0.f, 0.f, 0.f);
|
m_Rotation = glm::vec3(0.f, 0.f, 0.f);
|
||||||
m_Jumping = false;
|
m_Jumping = false;
|
||||||
|
m_CrouchingLastFrame = m_Crouching;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename EventContext>
|
template <typename EventContext>
|
||||||
|
|||||||
@@ -480,6 +480,7 @@ BoxTriRes AABBvsTriangle(const AABB& box,
|
|||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 cornerResolution = (1+t) * diagonal;
|
glm::vec3 cornerResolution = (1+t) * diagonal;
|
||||||
|
cornerResolution = glm::dot(cornerResolution, triNormal) * triNormal;
|
||||||
//Overwrite the smallest resolution if cornerResolution is smaller.
|
//Overwrite the smallest resolution if cornerResolution is smaller.
|
||||||
float lenSq = glm::length2(cornerResolution);
|
float lenSq = glm::length2(cornerResolution);
|
||||||
if (lenSq < resolveShortest.DistanceSq) {
|
if (lenSq < resolveShortest.DistanceSq) {
|
||||||
|
|||||||
@@ -96,12 +96,11 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
|
|||||||
glm::mat4 modelMatrix = Transform::ModelMatrix(boxB.Entity);
|
glm::mat4 modelMatrix = Transform::ModelMatrix(boxB.Entity);
|
||||||
|
|
||||||
glm::vec3 inOutVelocity = (glm::vec3)cPhysics["Velocity"];
|
glm::vec3 inOutVelocity = (glm::vec3)cPhysics["Velocity"];
|
||||||
bool notMovingxz = glm::all(glm::lessThan(glm::abs(glm::vec2(inOutVelocity.x, inOutVelocity.z)), glm::vec2(0.01f))) && prevPosIt != m_PrevPositions.end();
|
|
||||||
bool isOnGround = (bool)cPhysics["IsOnGround"];
|
bool isOnGround = (bool)cPhysics["IsOnGround"];
|
||||||
float verticalStepHeight = (float)(double)cPhysics["VerticalStepHeight"];
|
float verticalStepHeight = (float)(double)cPhysics["VerticalStepHeight"];
|
||||||
if (Collision::AABBvsTriangles(boxA, model->Vertices(), model->m_Indices, modelMatrix, inOutVelocity, verticalStepHeight, isOnGround, resolutionVector)) {
|
if (Collision::AABBvsTriangles(boxA, model->Vertices(), model->m_Indices, modelMatrix, inOutVelocity, verticalStepHeight, isOnGround, resolutionVector)) {
|
||||||
//Move the position to previous position if it is not moving in the xz-plane, else resolve with the resolution vector.
|
//Move the position to previous position if it is not moving in the xz-plane, else resolve with the resolution vector.
|
||||||
(glm::vec3&)cTransform["Position"] += notMovingxz ? prevPosIt->second - boxA.Origin() : resolutionVector;
|
(glm::vec3&)cTransform["Position"] += resolutionVector;
|
||||||
boxA = *Collision::EntityAbsoluteAABB(entity);
|
boxA = *Collision::EntityAbsoluteAABB(entity);
|
||||||
cPhysics["Velocity"] = inOutVelocity;
|
cPhysics["Velocity"] = inOutVelocity;
|
||||||
if (isOnGround) {
|
if (isOnGround) {
|
||||||
|
|||||||
@@ -264,6 +264,11 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
|
|||||||
size = glm::vec3(1.f, 1.f, 1.f);
|
size = glm::vec3(1.f, 1.f, 1.f);
|
||||||
} else {
|
} else {
|
||||||
size = glm::vec3(1.f, 1.6f, 1.f);
|
size = glm::vec3(1.f, 1.6f, 1.f);
|
||||||
|
if (controller->CrouchingLastFrame() && isOnGround) {
|
||||||
|
// The collision should resolve this anyway, but
|
||||||
|
// this is more reliable, since the box gets larger.
|
||||||
|
((glm::vec3&)cTransform["Position"]).y += 0.3f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user