Allow moving while jumping. Disable gravity when grounded. Change some parameters.
This commit is contained in:
parent
36f2484663
commit
923a069408
@ -68,7 +68,7 @@ private:
|
|||||||
sphere.radius = m_characterShape->m_radius;
|
sphere.radius = m_characterShape->m_radius;
|
||||||
return sphere;
|
return sphere;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateGrounded()
|
void UpdateGrounded()
|
||||||
{
|
{
|
||||||
b3StackArray<b3Shape*, 32> shapes;
|
b3StackArray<b3Shape*, 32> shapes;
|
||||||
@ -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,8 +294,9 @@ private:
|
|||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
// Collect collision planes
|
||||||
b3Vec3 translation = solvePosition - startPosition;
|
b3Vec3 translation = solvePosition - startPosition;
|
||||||
|
|
||||||
CollectSweepPlanes(planes, shapes, translation);
|
CollectSweepPlanes(planes, shapes, translation);
|
||||||
|
|
||||||
solvePosition = SolvePositionConstraints(planes, targetPosition);
|
solvePosition = SolvePositionConstraints(planes, targetPosition);
|
||||||
@ -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,42 +545,48 @@ 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();
|
|
||||||
|
|
||||||
if (isGounded)
|
static b3Vec3 velocity = b3Vec3_zero;
|
||||||
|
|
||||||
|
velocity.x = 0.0f;
|
||||||
|
velocity.z = 0.0f;
|
||||||
|
|
||||||
|
extern GLFWwindow* g_window;
|
||||||
|
|
||||||
|
bool leftDown = glfwGetKey(g_window, GLFW_KEY_LEFT);
|
||||||
|
bool rightDown = glfwGetKey(g_window, GLFW_KEY_RIGHT);
|
||||||
|
bool downDown = glfwGetKey(g_window, GLFW_KEY_DOWN);
|
||||||
|
bool upDown = glfwGetKey(g_window, GLFW_KEY_UP);
|
||||||
|
bool spaceDown = glfwGetKey(g_window, GLFW_KEY_SPACE);
|
||||||
|
|
||||||
|
bool isGrounded = m_characterController->IsGrounded();
|
||||||
|
|
||||||
|
// Walk
|
||||||
|
if (leftDown)
|
||||||
{
|
{
|
||||||
extern GLFWwindow* g_window;
|
velocity.x -= walkSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
bool leftDown = glfwGetKey(g_window, GLFW_KEY_LEFT);
|
if (rightDown)
|
||||||
bool rightDown = glfwGetKey(g_window, GLFW_KEY_RIGHT);
|
{
|
||||||
bool downDown = glfwGetKey(g_window, GLFW_KEY_DOWN);
|
velocity.x += walkSpeed;
|
||||||
bool upDown = glfwGetKey(g_window, GLFW_KEY_UP);
|
}
|
||||||
bool spaceDown = glfwGetKey(g_window, GLFW_KEY_SPACE);
|
|
||||||
|
|
||||||
// Walk
|
if (upDown)
|
||||||
if (leftDown)
|
{
|
||||||
{
|
velocity.z -= walkSpeed;
|
||||||
velocity.x -= walkSpeed;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (rightDown)
|
if (downDown)
|
||||||
{
|
{
|
||||||
velocity.x += walkSpeed;
|
velocity.z += walkSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (upDown)
|
if (isGrounded)
|
||||||
{
|
{
|
||||||
velocity.z -= walkSpeed;
|
velocity.y = 0.0f;
|
||||||
}
|
|
||||||
|
|
||||||
if (downDown)
|
|
||||||
{
|
|
||||||
velocity.z += walkSpeed;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Jump
|
// Jump
|
||||||
if (spaceDown)
|
if (spaceDown)
|
||||||
@ -586,10 +594,12 @@ public:
|
|||||||
velocity.y += jumpSpeed;
|
velocity.y += jumpSpeed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
// Integrate gravity
|
{
|
||||||
velocity.y -= dt * gravity;
|
// Integrate 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