Hello, pretty much as the title says im trying to have 2 keybinds for sprinting. So the player can either use left shift or space. When left shift is used the game works perfectly, but when the player uses space the attacks don’t work properly. Ive tried using other keys instead of space and the same issue occurs. Is there a proper way to use multiple keys as i’ve just set both to sprint in the input bind menu. Thanks for any help!
Should have no issues, can you show the bit of code and a screen shot of the input bindings? The platform game template is an easy one to see how this works. You can open it up and simply add a and d as left and right along with the arrow keys already there and it works out of the box.
these are the input bindings.
this is the input handling:
function on_input(self, action_id, action)
--checks if sprint button is held and adjusts speed accordingly
if action_id == hash("sprint") then
if action.pressed then
self.speed = sprint_speed
elseif action.released then
self.speed = reg_speed
end
and then this is some of the atrack script, i dont see anything here that i can change to fix this problem:
if self.attack == true then
local angle = math.atan2(self.dir.y, self.dir.x)
local rot = vmath.quat_rotation_z(angle)
local props = { dir = self.dir }
factory.create("#player attack", nil, rot, props)
self.attacking = true
if self.dir.x > 0 then
anim = hash("attack-r")
elseif self.dir.x < 0 then
anim = hash("attack-l")
elseif self.dir.y > 0 then
anim = hash("attack-b")
elseif self.dir.y < 0 then
anim = hash("attack-f")
end
self.attack = false
self.attacking = false
attack_done = false
end
-- if shift isnt held, move at reg speed
if attack_done == true then
if self.attacking == false then
if self.speed == reg_speed then
if self.dir.x > 0 then
anim = hash("player-right")
self.moving = true
elseif self.dir.x < 0 then
anim = hash("player-left")
self.moving = true
elseif self.dir.y > 0 then
anim = hash("player-back")
self.moving = true
elseif self.dir.y < 0 then
anim = hash("player-front")
self.moving = true
end
-- if sprint button is held move wih increased speed and sprint animations
elseif self.speed == sprint_speed then
if self.dir.x > 0 then
anim = hash("player-right")
self.moving = true
elseif self.dir.x < 0 then
anim = hash("player-left")
self.moving = true
elseif self.dir.y > 0 then
anim = hash("sprint-b")
self.moving = true
elseif self.dir.y < 0 then
anim = hash("sprint-f")
self.moving = true
end
The best strategy for this task is to use a module like
This way you can not only assign different input buttons from different devices (keyboard, mouse, gamepad) to one action, but also allow the player to assign these buttons.
This problem is really strange.
And if you do, in the assignment:
Lshift = sprint
Space = sprints
And in the code:
if action_id == hash("sprint") or action_id == hash("sprints") then
Can you try to do this with the platform template with jump as Lshift and see if you can re-create. When I did this it worked as expected both LShift and Space cause the jump animation and function to trigger. Makes me think something odd in your code or project might be at play. Or you can give a link to the repo and I can look at it there.