basic controller command for character
This commit is contained in:
parent
39bd754e99
commit
ccbde75d9b
@ -11,6 +11,7 @@
|
||||
#include <SFML/System.hpp>
|
||||
|
||||
#define DEFAULT_ROTATION_SPEED 0.001f
|
||||
#define TRIGGER_VALUE 15
|
||||
|
||||
void FirstPersonCamera::computeView()
|
||||
{
|
||||
@ -62,6 +63,7 @@ const float LEGS_HEIGHT = 1.f;
|
||||
const float EYES_OFFSET = 0.3f;
|
||||
const float JUMP_VELOCITY = 5.f;
|
||||
|
||||
|
||||
PlayerCharacterNode::PlayerCharacterNode(bool noClip) :
|
||||
m_jumping(false),
|
||||
m_noclipMode(noClip),
|
||||
@ -119,8 +121,8 @@ void PlayerCharacterNode::update()
|
||||
Input *input = getEngine().getInput();
|
||||
float deltaTime = getEngine().getDeltaTime();
|
||||
|
||||
int walk = 0;
|
||||
int strafe = 0;
|
||||
float walk = 0;
|
||||
float strafe = 0;
|
||||
bool jump = false;
|
||||
bool run = false;
|
||||
|
||||
@ -144,7 +146,23 @@ void PlayerCharacterNode::update()
|
||||
else if(action.action == m_inputActions[TOGGLE_NOCLIP])
|
||||
toggleNoClip();
|
||||
}
|
||||
|
||||
glm::vec2 rotatecam = glm::vec2(0.f,0.f);
|
||||
std::vector<int> controllers = input->getControllersConnected();
|
||||
for (auto controller : controllers){
|
||||
float strafe_joy = input->getAxisPosition(controller, input::LEFT_JOYSTICK_HORIZONTAL);
|
||||
if (abs(strafe_joy) > TRIGGER_VALUE)
|
||||
strafe = strafe_joy;
|
||||
float forward = input->getAxisPosition(controller, input::LEFT_JOYSTICK_VERTICAL);
|
||||
if (abs(forward) > TRIGGER_VALUE)
|
||||
walk = -forward;
|
||||
float pitch_joy = input->getAxisPosition(controller,input::RIGHT_JOYSTICK_HORIZONTAL);
|
||||
if (abs(pitch_joy) > TRIGGER_VALUE)
|
||||
rotatecam.x = pitch_joy;
|
||||
float yaw_joy = input->getAxisPosition(controller,input::RIGHT_JOYSTICK_VERTICAL);
|
||||
if (abs(yaw_joy) > TRIGGER_VALUE)
|
||||
rotatecam.y = yaw_joy;
|
||||
}
|
||||
m_fpsCamera.rotate(rotatecam.x,rotatecam.y);
|
||||
// update camera rotation
|
||||
glm::vec2 diff = input->getDeltaPosition();
|
||||
m_fpsCamera.rotate(diff.x, diff.y);
|
||||
@ -176,6 +194,7 @@ void PlayerCharacterNode::update()
|
||||
targetVelocity.setZ(hPos.y);
|
||||
}
|
||||
}
|
||||
|
||||
// apply movements
|
||||
if(m_noclipMode)
|
||||
{
|
||||
@ -187,14 +206,14 @@ void PlayerCharacterNode::update()
|
||||
else
|
||||
{
|
||||
bool onGround = false;
|
||||
btVector3 dir(moveDir.x/4,0,moveDir.z/4);
|
||||
btVector3 dir(moveDir.x/2.f,0.f,moveDir.z/2.f);
|
||||
btVector3 start_front(pos+dir);
|
||||
start_front.setY(pos.y() - TORSO_HEIGHT/2.f);
|
||||
btVector3 end_front(start_front);
|
||||
end_front.setY(end_front.y() - (LEGS_HEIGHT*2.f));
|
||||
btCollisionWorld::ClosestRayResultCallback RayCallback_front(start_front, end_front);
|
||||
|
||||
btVector3 start_back(pos-dir);
|
||||
btVector3 start_back(pos);
|
||||
start_back.setY(pos.y() - TORSO_HEIGHT/2.f);
|
||||
btVector3 end_back(start_back);
|
||||
end_back.setY(end_back.y() - (LEGS_HEIGHT));
|
||||
@ -214,7 +233,8 @@ void PlayerCharacterNode::update()
|
||||
float slope = normal_back.dot(btVector3(0,1,0));
|
||||
controlRatio = slope > 0.4f ? 0.2f * slope : 0.f;
|
||||
|
||||
if (RayCallback_front.hasHit()){
|
||||
if (RayCallback_front.hasHit())
|
||||
{
|
||||
float displacement = RayCallback_front.m_hitPointWorld.y() - (end_front.y() + start_front.y())/2.f;
|
||||
if(abs(displacement) > 0.1f)
|
||||
pos.setY(pos.y() + deltaTime*0.01f*(displacement > 0 ? 1 : -1));
|
||||
|
Loading…
x
Reference in New Issue
Block a user