Allow moving while jumping. Disable gravity when grounded. Change some parameters.
This commit is contained in:
parent
36f2484663
commit
923a069408
@ -278,6 +278,7 @@ private:
|
|||||||
b3StackArray<b3Shape*, 32> shapes;
|
b3StackArray<b3Shape*, 32> shapes;
|
||||||
CollectStaticShapes(shapes);
|
CollectStaticShapes(shapes);
|
||||||
|
|
||||||
|
// Collect collision planes
|
||||||
b3StackArray<Plane, 32> planes;
|
b3StackArray<Plane, 32> planes;
|
||||||
CollectOverlapPlanes(planes, shapes);
|
CollectOverlapPlanes(planes, shapes);
|
||||||
|
|
||||||
@ -293,6 +294,7 @@ private:
|
|||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
// Collect collision planes
|
||||||
b3Vec3 translation = solvePosition - startPosition;
|
b3Vec3 translation = solvePosition - startPosition;
|
||||||
|
|
||||||
CollectSweepPlanes(planes, shapes, translation);
|
CollectSweepPlanes(planes, shapes, translation);
|
||||||
@ -309,7 +311,7 @@ private:
|
|||||||
oldSolvePosition = solvePosition;
|
oldSolvePosition = solvePosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update body
|
// Synchronize body
|
||||||
b3Quat orientation = m_characterBody->GetOrientation();
|
b3Quat orientation = m_characterBody->GetOrientation();
|
||||||
|
|
||||||
b3Vec3 axis;
|
b3Vec3 axis;
|
||||||
@ -543,14 +545,14 @@ public:
|
|||||||
float32 dt = g_testSettings->inv_hertz;
|
float32 dt = g_testSettings->inv_hertz;
|
||||||
|
|
||||||
const float32 walkSpeed = 10.0f;
|
const float32 walkSpeed = 10.0f;
|
||||||
const float32 jumpSpeed = 300.0f;
|
const float32 jumpSpeed = 10.0f;
|
||||||
const float32 gravity = 50.0f * 9.8f;
|
const float32 gravityAcc = 9.8f;
|
||||||
b3Vec3 velocity = b3Vec3_zero;
|
|
||||||
|
|
||||||
bool isGounded = m_characterController->IsGrounded();
|
static b3Vec3 velocity = b3Vec3_zero;
|
||||||
|
|
||||||
|
velocity.x = 0.0f;
|
||||||
|
velocity.z = 0.0f;
|
||||||
|
|
||||||
if (isGounded)
|
|
||||||
{
|
|
||||||
extern GLFWwindow* g_window;
|
extern GLFWwindow* g_window;
|
||||||
|
|
||||||
bool leftDown = glfwGetKey(g_window, GLFW_KEY_LEFT);
|
bool leftDown = glfwGetKey(g_window, GLFW_KEY_LEFT);
|
||||||
@ -559,6 +561,8 @@ public:
|
|||||||
bool upDown = glfwGetKey(g_window, GLFW_KEY_UP);
|
bool upDown = glfwGetKey(g_window, GLFW_KEY_UP);
|
||||||
bool spaceDown = glfwGetKey(g_window, GLFW_KEY_SPACE);
|
bool spaceDown = glfwGetKey(g_window, GLFW_KEY_SPACE);
|
||||||
|
|
||||||
|
bool isGrounded = m_characterController->IsGrounded();
|
||||||
|
|
||||||
// Walk
|
// Walk
|
||||||
if (leftDown)
|
if (leftDown)
|
||||||
{
|
{
|
||||||
@ -580,15 +584,21 @@ public:
|
|||||||
velocity.z += walkSpeed;
|
velocity.z += walkSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isGrounded)
|
||||||
|
{
|
||||||
|
velocity.y = 0.0f;
|
||||||
|
|
||||||
// Jump
|
// Jump
|
||||||
if (spaceDown)
|
if (spaceDown)
|
||||||
{
|
{
|
||||||
velocity.y += jumpSpeed;
|
velocity.y += jumpSpeed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// Integrate gravity
|
// Integrate gravity
|
||||||
velocity.y -= dt * gravity;
|
velocity.y -= dt * gravityAcc;
|
||||||
|
}
|
||||||
|
|
||||||
// Compute translation
|
// Compute translation
|
||||||
b3Vec3 translation = dt * velocity;
|
b3Vec3 translation = dt * velocity;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user