---nikoli Posted June 17, 2023 Share Posted June 17, 2023 Although I've successfully made a script that rotates back and forth +/- 45° on the 'Y' axis and attached it to a Hook5 mesh object CCTV camera, a camera image, and linked it to a screen to show an image like a real one would. I'm having issues figuring out how this game reads LUA's. Sync Test.mp4 My issue is I've been unable to figure out how to make them work if the mesh or the cameras initial orientation is something other than 0° on the 'Y' axis. This script works but only if the objects 'Y' orientation is set to 0°. I've been attempting to have it work with orientations other than 0° but so far, every script alteration I've tried either locks up the mesh and camera or locks up all scripts in the game until I close the game out and restart it. ------------------------------------------------------------------------------------------------------ local script = {} --SCRIPT BODY - any functions and calculations --==================================================================================================== --main function that will be used as frame update callback --id - object id allow access to object storage --delta - time passed from last frame, i.e frame time local function update( id, delta ) --here the main script things logic, calculations and so on local st = db.storage[id] if st then st.object.rotation = st.object.rotation + Vector3( 0, st.speed, 0 ) * delta if st.object.rotation.y >= 45 then st.speed = -st.speed elseif st.object.rotation.y <= -45 then st.speed = -st.speed end end end --================================================================================================ --BIND - this function called when object binded with script and allow register all desired callbacks --================================================================================================ function script:bind_to_object( st, binder )--object storage and callback binder --declare per object variables st.speed = 10 --degree in sec --register callback in array of active callbacks binder:add_callback( CALLBACK_GLOBAL, "on_frame_update", st.object.id, update ) --callback class --callback type --object id --function that will be used as callback end --==================================================================================================== --script registration db.script_list["sc_object_cctv"] = script Partial examples of failed attempts that lock/disable all scripts until restart. These 'should' work, but don't. --- Any suggestions would be welcome. Attempt 01 ------------------------------------------------------------------------------------------------------ local st = db.storage[id] if st then local currentRotation = st.object.CFrame:toEulerAnglesXYZ() st.object.rotation = currentRotation + Vector3( 0, st.speed, 0 ) * delta if st.object.rotation.y >= 45 then st.speed = -st.speed elseif st.object.rotation.y <= -45 then st.speed = -st.speed end end end Attempt 02 ------------------------------------------------------------------------------------------------------ local st = db.storage[id] if st then local currentRotation = st.object.CFrame:toEulerAnglesXYZ() local newRotation = CFrame.Angles(0, currentRotation.y + st.speed * delta, 0) st.object.CFrame = st.object.CFrame * newRotation if currentRotation.y >= math.rad(45) then st.speed = -st.speed elseif currentRotation.y <= math.rad(-45) then st.speed = -st.speed end end end Attempt 03 ------------------------------------------------------------------------------------------------------- local st = db.storage[id] if st then local currentRotation = st.object.CFrame:toEulerAnglesXYZ() local newRotation = CFrame.fromEulerAnglesXYZ(0, currentRotation.y + st.speed * delta, 0) st.object.CFrame = st.object.CFrame * newRotation if currentRotation.y >= math.rad(45) then st.speed = -st.speed elseif currentRotation.y <= math.rad(-45) then st.speed = -st.speed end end end ------------------------------------------------------------------------------------------------------- Link to comment
Recommended Posts