So I’ve been trying to make some 8 directional, and it works fine, except it seems like it only detects one key at a time.
I can press up to go up, but if I press down while pressing up it doesn’t stop and it continues to go up. I can press right to go right, but if I press up while pressing right it will just go up and not go diagonal.
Why am I getting this problem?
Here is my movement code, if it helps:
local speed = 8;
local input_x = { left = hash("move_left"), right = hash("move_right") };
local input_y = { up = hash("move_up"), down = hash("move_down") };
function init(self)
self.direction = vmath.vector3(0, 0, 0);
msg.post(".", "acquire_input_focus");
end
function update(self, dt)
local old_position = go.get_position(".");
local movement = vmath.vector3(speed * self.direction.x, speed * self.direction.y, 0);
go.set_position(old_position + movement, ".");
end
function on_input(self, action_id, action)
local new_direction = vmath.vector3(0, 0, 0);
if (action_id == input_x.left) then
new_direction.x = new_direction.x + -action.value;
end
if (action_id == input_x.right) then
new_direction.x = new_direction.x + action.value;
end
if (action_id == input_y.down) then
new_direction.y = new_direction.y + -action.value;
end
if (action_id == input_y.up) then
new_direction.y = new_direction.y + action.value;
end
self.direction = new_direction;
end