Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Title: Basic Camera with Axel
- --By: utrain
- --Description: Allows for basic camera movements
- --It uses bindKeyToPressed from this repo: https://github.com/u-train/utilityKeyBindfunctions-Teverse/blob/master/bindUtility.lua
- --However, it has been pasted since require isn't available for scripts on the machine on verison 0.19.0.
- --Intended to work on a Teverse environment on 0.19.0
- local function bindKeyToPressed(keyName, functionOnPressed, functionOnRelease)
- --Make sure the function doesn't error because of missing table field; give best feedback.
- assert(keyName, "keyName argument is nil.")
- local enumKey = enums.key[keyName]
- assert(enumKey, "keyName is not a vaild argument.")
- assert(type(functionOnPressed) == "function", "functionOnPressed is not a vaild argument.")
- --functionOnRelease is an optional argument
- if functionOnRelease then
- assert(type(functionOnRelease) == "function", "functionOnRelease is not a vaild argument.")
- end
- local debounce = false
- local onKeyPressConnection = engine.input:on("keyPressed", function(inputObject)
- if debounce then return end
- if inputObject.key == enumKey then
- debounce = true
- functionOnPressed(inputObject)
- end
- end)
- local onKeyReleaseConnection = engine.input:on("keyReleased", function(inputObject)
- if not debounce then return end
- if inputObject.key == enumKey then
- debounce = false
- if functionOnRelease then
- functionOnRelease(inputObject)
- end
- end
- end)
- --listOfDeconstructor
- return function()
- onKeyPressConnection:disconnect()
- onKeyPressConnection = nil
- onKeyReleaseConnection:disconnect()
- onKeyReleaseConnection = nil
- end
- end
- --Objects
- --The axel of life.
- local Center;
- local Blocks = {};
- do
- Blocks[1] = engine.construct("block", engine.workspace, {
- position = vector3(0,0,0);
- size = vector3(2,0.1,0.1);
- colour = colour(1,0,0);
- })
- Blocks[2] = engine.construct("block", engine.workspace, {
- position = vector3(0,0,0);
- size = vector3(0.1,2,0.1);
- colour = colour(0,1,0);
- })
- Blocks[3] = engine.construct("block", engine.workspace, {
- position = vector3(0,0,0);
- size = vector3(0.1,0.1,2);
- colour = colour(0,0,1);
- })
- Center = engine.construct("block", engine.workspace, {
- position = vector3(0,0,0);
- size = vector3(0.1,0.1,0.1);
- opacity = 0;
- })
- end
- --Textbox informing player of coordinates
- local CoordinateBox = engine.construct("guiTextBox", engine.interface, {
- size = guiCoord(1, 0, 0, 25);
- textColour = colour(0, 0, 0);
- })
- local camera = engine.workspace.camera
- --Stores the deconstructors for the binds.
- local listOfDeconstructor = {}
- --Whenever camera positions moves, it will run this.
- local function Update()
- camera:lookAt(Center.position)
- CoordinateBox.text = ("Position: %s, %s, %s; press 'C' to clear everything."):format(camera.position.x, camera.position.y, camera.position.z)
- end
- --Start it.
- camera.position = vector3(2, 2, 2)
- Update()
- --All of the hotkeys.
- listOfDeconstructor[#listOfDeconstructor + 1] = bindKeyToPressed("d", function()
- camera.position = vector3(camera.position.x + 0.5, camera.position.y, camera.position.z)
- Update()
- end)
- listOfDeconstructor[#listOfDeconstructor + 1] = bindKeyToPressed("a", function()
- camera.position = vector3(camera.position.x - 0.5, camera.position.y, camera.position.z)
- Update()
- end)
- listOfDeconstructor[#listOfDeconstructor + 1] = bindKeyToPressed("w", function()
- camera.position = vector3(camera.position.x, camera.position.y, camera.position.z + 0.5)
- Update()
- end)
- listOfDeconstructor[#listOfDeconstructor + 1] = bindKeyToPressed("s", function()
- camera.position = vector3(camera.position.x, camera.position.y, camera.position.z - 0.5)
- Update()
- end)
- listOfDeconstructor[#listOfDeconstructor + 1] = bindKeyToPressed("q", function()
- camera.position = vector3(camera.position.x, camera.position.y + 0.5, camera.position.z )
- Update()
- end)
- listOfDeconstructor[#listOfDeconstructor + 1] = bindKeyToPressed("e", function()
- camera.position = vector3(camera.position.x, camera.position.y - 0.5, camera.position.z)
- Update()
- end)
- --To clear everything afterwards
- listOfDeconstructor[#listOfDeconstructor + 1] = bindKeyToPressed("c", function()
- for _, deconstructors in next, listOfDeconstructor do
- deconstructors()
- end
- for _, block in next, Blocks do
- block:destroy()
- end
- Center:destroy()
- CoordinateBox:destroy()
- --Don't need to run lookAt because it is already facing 0, 0, 0
- camera.position = vector3(0, 0, 0)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement