Write a stormworks microcontroller lua script for camera guided missile
- User
Write a stormworks microcontroller lua script for camera guided missile
- Assistant
Sure! Here's a simple Stormworks microcontroller Lua script for a camera guided missile:
function onTick() -- Get the missile entity local entity = this:getClosestLuaControlledMissile() if not entity then return end local target = getTarget() if not target then return end local missilePosition = entity:getPosition() local targetPosition = target:getPosition() -- Calculate the direction vector towards the target local direction = targetPosition - missilePosition direction:normalize() -- Rotate the missile towards the target local missileRotation = entity:getTransform():getRotation() local desiredRotation = direction:toRotation() local rotationError = desiredRotation - missileRotation entity:applyRotation(rotationError, 1) -- Launch the missile towards the target entity:applyThrust(1) end function getTarget() -- Find the camera entity with the "Target" tag local cameras = this:getAllCameras() for _, camera in ipairs(cameras) do if camera:hasTag("Target") then return camera end end return nil end