diff --git a/data/scripts/player_fps.lua b/data/scripts/player_fps.lua index 865a74b2a..54d4db058 100644 --- a/data/scripts/player_fps.lua +++ b/data/scripts/player_fps.lua @@ -1,8 +1,10 @@ local forward = 0 +local backward = 0 local left = 0 local right = 0 local yaw = 0 local sprint = 0 +local jump = 0 function onInputEvent(event : InputEvent) if event.type == "axis" and event.device.type == "mouse" then @@ -17,29 +19,43 @@ function onInputEvent(event : InputEvent) forward = 0 end end - if event.key_id == LumixAPI.INPUT_KEYCODE_LEFT then + if event.key_id == string.byte("S") then + if event.down then + backward = 1 + else + backward = 0 + end + end + if event.key_id == string.byte("A") then if event.down then left = 1 else left = 0 end end - if event.key_id == LumixAPI.INPUT_KEYCODE_RIGHT then + if event.key_id == string.byte("D") then if event.down then right = 1 else right = 0 end end - if event.key_id == LumixAPI.INPUT_KEYCODE_SHIFT then + if event.key_id == LumixAPI.INPUT_KEYCODE_SHIFT then if event.down then sprint = 1 else sprint = 0 end - end + end + if event.key_id == LumixAPI.INPUT_KEYCODE_SPACE then + if event.down then + jump = 1 + else + jump = 0 + end + end end - end + end end function onControllerHit(obj) @@ -48,21 +64,41 @@ function onControllerHit(obj) a:applyForce(dir) end - function update(td) - local speed = 0 - if forward == 1 then - if sprint == 1 then - speed = 6 - else - speed = 3 - end + local speed = 3 + local disp_x = 0 + local disp_z = 0 + local disp_y = 0 + + if forward == 1 then + if sprint == 1 then + speed = 6 + else + speed = 3 + end + disp_z = td * -speed + end + + if backward == 1 then + disp_z = td * speed + end + + if left == 1 then + disp_x = td * -speed + end + + if right == 1 then + disp_x = td * speed + end + + if jump == 1 then + disp_y = td * speed end local a2 = yaw * 0.5 this.rotation = {0, math.sin(a2), 0, math.cos(a2) } - local disp = td * -speed - local dir = {math.sin(yaw) * disp, 0, math.cos(yaw) * disp} - this.physical_controller:move(dir) -end \ No newline at end of file + local dir_x = math.sin(yaw) * disp_z + math.cos(yaw) * disp_x + local dir_z = math.cos(yaw) * disp_z - math.sin(yaw) * disp_x + this.physical_controller:move({dir_x, disp_y, dir_z}) +end