diff options
author | sanine-a <sanine.not@pm.me> | 2023-05-09 16:02:43 -0500 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2023-05-09 16:02:43 -0500 |
commit | 68ef488e8f3bafa0ed68eb8326ac26fd63416891 (patch) | |
tree | 39773fcf0f42d3e05600ad437d90df884b3f6d63 /scripts | |
parent | 9c9690ab5e4ecb484ee130c21f1767785908bd10 (diff) |
create more globals in honey.std
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/capsuleMove.lua | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/scripts/capsuleMove.lua b/scripts/capsuleMove.lua new file mode 100644 index 0000000..e454b06 --- /dev/null +++ b/scripts/capsuleMove.lua @@ -0,0 +1,37 @@ +require 'honey.std' + +return function(entities, id, dt) + local self = honey.ecs.Accessor(entities, id) + local pressed = function(key) + return glfw.GetKey(window.win, key) == glfw.PRESS + end + + local yaw = math.rad( + self.node._child.p + .node._child.pivot + .pitchyaw.yaw) + local forward = Vec3{-math.sin(yaw), 0, -math.cos(yaw)} + local left = Vec3{-math.cos(yaw), 0, math.sin(yaw)} + + local vel = Vec3{0,0,0} + + if pressed(glfw.KEY_W) then + vel = vel + forward + end + if pressed(glfw.KEY_A) then + vel = vel + left + end + if pressed(glfw.KEY_S) then + vel = vel - forward + end + if pressed(glfw.KEY_D) then + vel = vel - left + end + + vel = 1000 * vel:normalize() + + x, y, z = ode.BodyGetLinearVel(self.physics._body) + if Vec3{x,y,z}:norm2() < 500 then + ode.BodyAddForce(self.physics._body, vel[1], vel[2], vel[3]) + end +end |