Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/thoda-dev/du-default-autoconf. default autoconfig files from Dual Universe
Something went wrong. Try again.
3.7 kB · 84 lines
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485# This is a file describing a standard autoconfiguration, do not edit.# See custom/sample.conf for a more generic template and explanation on the syntax.
name: ui_cu_autoconf_pvp_ecu
slots: core: class: CoreUnit antigrav: class: AntiGravityGeneratorUnit container: class: FuelContainer select: all gyro: class: GyroUnit
handlers: unit: onStart: lua: | Nav = Navigator.new(system, core, unit) planetInfluenceThreshold = 0.6 if antigrav ~= nil then antigrav.activate() antigrav.show() end system: onFlush: lua: | local verticalAutoLandingSpeed = 20 --export: Vertical auto landing speec in km/h local power = 3 local worldUp = vec3(core.getConstructWorldOrientationUp()) local worldForward = vec3(core.getConstructWorldOrientationForward()) local worldRight = vec3(core.getConstructWorldOrientationRight()) local worldVertical = vec3(core.getWorldVertical())
-- are we in deep space or are we near a planet ? local planetInfluence = Nav.control.getClosestPlanetInfluence() if planetInfluence > 0 then -- stabilize orientation along the gravity if (rollPID == nil) then rollPID = pid.new(0.2, 0, 10) pitchPID = pid.new(0.2, 0, 10) end
local yawVelocity = vec3(core.getWorldAngularVelocity()):dot(worldUp) local currentRoll = getRoll(worldVertical, worldForward, worldRight) local currentPitch = -math.asin(worldForward:dot(worldVertical)) * constants.rad2deg rollPID:inject(-currentRoll) pitchPID:inject(-currentPitch) local yawAcceleration = - power * yawVelocity angularAcceleration = rollPID:get() * worldForward + pitchPID:get() * worldRight + yawAcceleration * worldUp else -- cancel rotation local worldAngularVelocity = vec3(core.getWorldAngularVelocity()) angularAcceleration = - power * worldAngularVelocity end
if planetInfluence > planetInfluenceThreshold then -- go down at verticalTargetSpeed when very close to a planet targetVelocity = (verticalAutoLandingSpeed / 3.6) * worldVertical else -- immobilize ship when not targetVelocity = vec3() end Nav:setEngineCommand('torque', vec3(), angularAcceleration) stabilization = power * (targetVelocity - vec3(core.getWorldVelocity())) Nav:setEngineCommand('vertical, brake, horizontal', stabilization -vec3(core.getWorldGravity()), vec3(), false) onUpdate: lua: | local accelThreshold = 0.1 local speedThreshold = 0.1
-- auto stopping mechanism when immobile and close to planet local accel = vec3(Nav.core.getWorldAcceleration()):len() local speed = vec3(Nav.core.getWorldVelocity()):len() if accel < accelThreshold and speed < speedThreshold and Nav.control.getClosestPlanetInfluence() > planetInfluenceThreshold then unit.exit() end