Jump to content

Recommended Posts

Posted

I am not sure if I am doing something wrong or whether this is a bug. My characters movement seems to work fine at first, but after some walking around, I notice that the strafing no longer works correct. sometimes I go into the opposite direction of where I want to go. The example attached shows that strafe walking doesn't function properly and that jumping has some issues as well.

 

 

 

//Get the mouse movement
Vec3 currentMousePos = window->GetMousePosition();
mouseDifference.x = currentMousePos.x - centerMouse.x;
mouseDifference.y = currentMousePos.y - centerMouse.y;


//Adjust and set the camera rotation
camRotation.x += mouseDifference.y / mouseSensitivity;
camRotation.y += mouseDifference.x / mouseSensitivity;
camera->SetRotation(camRotation);
window->SetMousePosition(centerMouse.x, centerMouse.y);


//Player Movement
playerMovement.x = (window->KeyDown(Key:) - window->KeyDown(Key::A)) * Time::GetSpeed() * strafeSpeed;
playerMovement.z = (window->KeyDown(Key::W) - window->KeyDown(Key::S)) * Time::GetSpeed() * moveSpeed;

//Update the player
player->SetInput(camRotation.y, playerMovement.z, playerMovement.x, 0, crouched, 0.5);

Vec3 playerPos = player->GetPosition();
camera->SetPosition(playerPos.x, playerPos.y + 1.8, playerPos.z);

 

 

Jumping also has problems. I have this really simple code that lets the player jump. Unfortunately this only works sporadicly, after hitting the space key a 10 to 20 times. The weird thing is, when you leave out the check for the Space key being pressed, the character jumps perfectly normal (although it keeps jumping ofcourse, since we no longer check for key pressing).

 

// Check for jumping
float tempJumpForce = 0;
if(window->KeyHit(Key::Space) && player->GetAirborne())
tempJumpForce = 10;

//Update the player
player->SetInput(0, 0, 0, tempJumpForce , false, 1);

Any body else getting these results?

Posted

When I wanted to record the project to show what is going on, somehow the jumping worked. It turns out that the FPS causes the jumping to either work or not work. After setting the vsync to true (60 fps) jumping works normally. without vsync I have 800 fps.

Posted

The physics is updated at 60 hz, regardless of framerate. It's really best to call SetInput in the UpdatePhysics callback, because then you can be sure jumps will make it into the next physics update.

 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...