Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard support #21

Open
Flix01 opened this issue Mar 1, 2023 · 2 comments
Open

Keyboard support #21

Flix01 opened this issue Mar 1, 2023 · 2 comments

Comments

@Flix01
Copy link

Flix01 commented Mar 1, 2023

Hi, I've seen that a gamepad is mandatory, and that the "keyboard support patch" proposed here has a broken link.

Here are my changes in file controller.cpp:

vec3 gamepad_get_stick(int stick, const float deadzone = 0.2f)
{
// I've replaced all the original content of this function with the following:
vec3 pad(0,0,0);float am = 1.f;
if (IsKeyDown(KEY_RIGHT_SHIFT) || IsKeyDown(KEY_LEFT_SHIFT)) am*=0.5f;  // use SHIFT to slow down/walk
if (IsKeyDown(KEY_RIGHT_CONTROL) || IsKeyDown(KEY_LEFT_CONTROL)) am*=2.f; // use CTRL to speed up
if (stick==GAMEPAD_STICK_LEFT)	{
        // use ARROW keys to move the character
	if (IsKeyDown(KEY_RIGHT)) pad.x+=am;
	if (IsKeyDown(KEY_LEFT)) pad.x-=am; 
	if (IsKeyDown(KEY_UP)) pad.z-=am;
	if (IsKeyDown(KEY_DOWN)) pad.z+=am;
}
else if (stick==GAMEPAD_STICK_RIGHT)	{
        // use the number pad to move the camera
	if (IsKeyDown(KEY_KP_6)) pad.x-=am;
	if (IsKeyDown(KEY_KP_4)) pad.x+=am; 
	if (IsKeyDown(KEY_KP_8)) pad.z+=am;
	if (IsKeyDown(KEY_KP_2)) pad.z-=am;
}
return pad;
}

This works for me (I'm on Ubuntu Linux).
I'm not making a pull request. I've just posted my code here in case somebody is interested.

@orangeduck: feel free to close this issue whenever you want, and thanks for sharing the project!

@orangeduck
Copy link
Owner

Thanks!

@Maekdzp
Copy link

Maekdzp commented Mar 3, 2023

Thanks for the keyboard support. And I notice that strafe support is missing, which is quite simple. In case you just forgot that, here are my changes in controller.cpp:

bool desired_strafe_update()
{
    //return IsGamepadButtonDown(GAMEPAD_PLAYER, GAMEPAD_BUTTON_LEFT_TRIGGER_2) > 0.5f;
    return IsKeyDown(KEY_LEFT_ALT); // use left ALT to strafe
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants