diff options
author | sanine <sanine.not@pm.me> | 2023-05-10 23:59:04 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-05-10 23:59:04 -0500 |
commit | 14195dac1eda9140192ca07003258715b8b0abd3 (patch) | |
tree | bb4e41153363c791d4a9c7948bc85e0d4f77bc98 /character.lua | |
parent | 26bfc10ad0e8a355e9b02946dd31642f49a6ec60 (diff) |
implement basic floating-ray character controller
Diffstat (limited to 'character.lua')
-rw-r--r-- | character.lua | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/character.lua b/character.lua new file mode 100644 index 0000000..431e473 --- /dev/null +++ b/character.lua @@ -0,0 +1,97 @@ +require 'honey.std' + +return function(db) + local capsule = db:createEntityWithComponents{ + node = { + matrix = Mat4() + :identity() + :translate(Vec3{0,10,0}) + :rotateX(0.5*math.pi) + }, + collision = { + class = "capsule", + radius = 1, + length = 2, + category = 2, + collide = bit.bxor(0xffffffff, 2) + }, + physics = { + mass = { + class = "capsule", + mass = 10, + direction = 3, + radius = 1, + length = 2, + }, + surface = true, + maxAngularSpeed = 0, + }, + renderMesh = { + mesh = { filename="assets/capsule.obj", index=1 }, + shader = { vertex="vertex.glsl", fragment="fragment.glsl" }, + textures = { + ourTexture = { filename = "assets/green-grass.jpg" }, + }, + }, + script = { script = "scripts.capsuleMove" }, + } + + + local spring = db:createEntityWithComponents{ + node = { + name = "spring", + parent = capsule, + matrix = Mat4():identity() + :translate(Vec3{0,-1,0}) + }, + collision = { + class = "ray", + length = 4, + category = 2, + collide = bit.bxor(0xffffffff, 2) + }, + onCollision = { + script = "scripts.character.spring", + }, + spring = { + F = 0, + } + } + + + local pivotPivot = db:createEntityWithComponents{ + node = { + name = "p", + parent = capsule, + matrix = Mat4():identity():rotateX(-0.5*math.pi), + }, + } + + + local capcamPivot = db:createEntityWithComponents{ + node = { + name = "pivot", + parent = pivotPivot, + matrix = Mat4():identity(), + }, + pitchyaw = { + pitch = 0, + yaw = 0, + }, + onCursorPos = { script = "scripts.cameraPivot" }, + } + + + local capcam = db:createEntityWithComponents{ + camera = { + projection = Mat4():perspective(math.rad(45), 640/480, 0.1, 1000), + render="screen", + }, + node = { + parent = capcamPivot, + matrix = Mat4():identity():translate(Vec3{0,0,20}), + }, + onScroll = { script = "scripts.character.cameraDistance" }, + onFramebufferSize = { script = "scripts.cameraHandleResize" }, + } +end |