fixed ground detection for jumping
This commit is contained in:
parent
71fd9e8b83
commit
4a8cbaf57f
@ -59,7 +59,7 @@ const float PLAYER_RADIUS = 0.30f;
|
||||
const float PLAYER_HEIGHT = 1.75f;
|
||||
const float EYES_OFFSET = 0.775f;
|
||||
const float JUMP_VELOCITY = 5.f;
|
||||
const float EPSILON = 1.f;
|
||||
const float EPSILON = 1.5f;
|
||||
|
||||
PlayerCharacterNode::PlayerCharacterNode(bool noClip) :
|
||||
m_noclipMode(noClip),
|
||||
@ -172,25 +172,25 @@ void PlayerCharacterNode::update()
|
||||
}
|
||||
else
|
||||
{
|
||||
float controlRatio = 0.2f; // 1 = total control, 0 = no control, can be seen as a slipperiness factor
|
||||
btVector3 newVelocity = velocity*(1.f-controlRatio) + targetVelocity*controlRatio;
|
||||
if(jump)
|
||||
{/*
|
||||
btVector3 start(pos);
|
||||
start.setY(start.y() - PLAYER_HEIGHT/2.f);
|
||||
btVector3 end(pos);
|
||||
end.setY(end.y() - EPSILON);
|
||||
btCollisionWorld::ClosestRayResultCallback RayCallback(start, end);
|
||||
getEngine().getPhysics()->rayTest(start, end, RayCallback);
|
||||
if(RayCallback.hasHit()) // if ground is nearby
|
||||
{
|
||||
//btVector3 normal = RayCallback.m_hitNormalWorld;
|
||||
|
||||
}*/
|
||||
|
||||
// raycasting not working yet
|
||||
newVelocity.setY(JUMP_VELOCITY);
|
||||
bool onGround = false;
|
||||
btVector3 start(pos);
|
||||
start.setY(start.y() - PLAYER_HEIGHT/2.f);
|
||||
btVector3 end(pos);
|
||||
end.setY(end.y() - EPSILON);
|
||||
btCollisionWorld::ClosestRayResultCallback RayCallback(start, end);
|
||||
getEngine().getPhysics()->rayTest(start, end, RayCallback);
|
||||
float controlRatio = 0.f; // 1 = total control, 0 = no control, can be seen as a slipperiness factor
|
||||
if(RayCallback.hasHit()) // if ground is nearby
|
||||
{
|
||||
onGround = true;
|
||||
btVector3 normal = RayCallback.m_hitNormalWorld;
|
||||
float slope = normal.dot(btVector3(0, 1, 0));
|
||||
controlRatio = slope > 0.4f ? 0.2f * slope : 0.f;
|
||||
}
|
||||
|
||||
btVector3 newVelocity = velocity*(1.f-controlRatio) + targetVelocity*controlRatio;
|
||||
if(jump && onGround)
|
||||
newVelocity.setY(JUMP_VELOCITY);
|
||||
m_rigidBody->setLinearVelocity(newVelocity);
|
||||
}
|
||||
m_playerLightNode->update();
|
||||
|
Loading…
x
Reference in New Issue
Block a user