Code:
Countdown = ui.MediaPlayer('sounds/countdown.mp3')
function script.startingSequence(dt)
if not INI.countdown then return end
if (SIM.isPaused or SIM.isInMainMenu) and Countdown then
Countdown:pause()
end
local centery = ac.getUI().windowSize.y / 2
local centerx = ac.getUI().windowSize.x / 2
local textToWrite = math.floor(SIM.timeToSessionStart / 1000) + 1
local firstCount = (SIM.timeToSessionStart / 1000 + 1) % 1
if textToWrite > 3 or textToWrite < 1 then return end
if textToWrite == 3 and INI.countdownSound then
Countdown:setVolume(ac.getAudioVolume(ac.AudioChannel.Main) * (INI.countdownSoundMulti + 0.35))
Countdown:play()
end
ui.setCursor(vec2(centerx - scale(240), centery - scale(240)))
ui.image('img/countdown-stripes.png', scaledVec2(480, 480), rgbm.colors.white)
local easeInValue = inSine(firstCount * 1000, 0, 1, 1000)
local easeOutValue = outInSine(firstCount * 1000, 0, 1, 1000)
if firstCount > 0.5 then
ui.pathArcTo(vec2(centerx, centery), scale(240 - (12 / 2)),
getAngle(0),
getAngle(360 - 360 * (((easeInValue - 0.5) / 0.5 * 1))), 80)
else
ui.pathArcTo(vec2(centerx, centery), scale(240 - (12 / 2)),
getAngle(360 - 360 * easeOutValue / 0.5 * 1),
getAngle(360), 80)
end
ui.pathStroke(rgbm.colors.white, false, scale(12))
ui.pushDWriteFont('Arkitech:\\fonts;Weight=Regular')
ui.setCursor(vec2(centerx - scale(400), centery - scale(240)))
ui.dwriteTextAligned(textToWrite, scale(160), ui.Alignment.Center, ui.Alignment.Center,
scaledVec2(800, 480), false, rgbm.colors.white)
ui.popDWriteFont()
end
AnimTimer = 0
local CarDimToAdd = vec2(CAR.aabbSize.x / 2, CAR.aabbSize.y * 1.4)
local waitingPosS1 = vec3(-2 - CarDimToAdd.x, 1, 1.5 + CarDimToAdd.y)
local waitingPosE1 = vec3(-2 - CarDimToAdd.x, 1, 3 + CarDimToAdd.y)
local waitingPosS2 = vec3(-1 - CarDimToAdd.x, 1, -3 - CarDimToAdd.y)
local waitingPosE2 = vec3(1 + CarDimToAdd.x, 0.4, -3 - CarDimToAdd.y)
local waitingPosS3 = vec3(-1 - CarDimToAdd.x, 1, 3 + CarDimToAdd.y)
local waitingPosE3 = vec3(1 + CarDimToAdd.x, 0.4, 3 + CarDimToAdd.y)
function countdownCamera(dt)
if SIM.isPaused or SIM.isInMainMenu then
if CameraMotion then
CameraMotion.transform = CameraMotion.transformOriginal
CameraMotion:dispose()
end
INITCAM = false
ACTIVECAMERAPOINT = 0
return
end
if SIM.timeToSessionStart < -2000 then return end
if SIM.timeToSessionStart > 19000 then
INITCAM = false
ACTIVECAMERAPOINT = 0
return
end
if CAR.isInPit and CameraMotion then
if CameraMotion then
CameraMotion.transform = CameraMotion.transformOriginal
CameraMotion:dispose()
end
return
end
if not INITCAM then
if CameraMotion then CameraMotion:dispose() end
CameraMotion = ac.grabCamera('starting anim')
INITCAM = true
end
if SIM.timeToSessionStart > 0 and ACTIVECAMERAPOINT == 0 then
ACTIVECAMERAPOINT = 4
AnimTimer = SIM.timeToSessionStart / 1000 - 3
end
if ACTIVECAMERAPOINT == 1 then
if AnimTimer > 0 then
AnimTimer = AnimTimer - dt
if CameraMotion then
local localPos = math.lerp(waitingPosS1, waitingPosE1, (1 - AnimTimer))
CameraMotion.transform.position = CAR.transform:transformPoint(localPos)
CameraMotion.transform.look = -CAR.transform:transformVector(localPos)
CameraMotion.transform.up = vec3(0, 1, 0)
end
else
ACTIVECAMERAPOINT = 2
AnimTimer = 1
end
end
if ACTIVECAMERAPOINT == 2 then cameraTransition(dt, waitingPosS2, waitingPosE2, 3) end
if ACTIVECAMERAPOINT == 3 then cameraTransition(dt, waitingPosS3, waitingPosE3, 4) end
if ACTIVECAMERAPOINT == 4 then
if AnimTimer > 0 then
AnimTimer = AnimTimer - dt / 1
if CameraMotion then
local localPos = waitingPosE3
CameraMotion.transform.position = CAR.transform:transformPoint(localPos)
CameraMotion.transform.look = -CAR.transform:transformVector(localPos)
CameraMotion.transform.up = vec3(0, 1, 0)
CameraMotion.ownShare = math.smoothstep(math.lerpInvSat(AnimTimer, 0, 1))
end
else
ACTIVECAMERAPOINT = 0
CameraMotion:dispose()
end
end
end
function cameraTransition(dt, startPos, endPos, nextPoint)
if AnimTimer > 0 then
AnimTimer = AnimTimer - dt
if CameraMotion then
local localPos = math.lerp(startPos, endPos, (1 - AnimTimer) ^ 0.4)
CameraMotion.transform.position = CAR.transform:transformPoint(localPos)
CameraMotion.transform.look = -CAR.transform:transformVector(localPos)
CameraMotion.transform.up = vec3(0, 1, 0)
end
else
ACTIVECAMERAPOINT = nextPoint
AnimTimer = 1
end
physics.awakeCar(0)
physics.engageGear(0, 1)
awakeFor = awakeFor + 5
end
I notice that Lua apps can get the exact starting time(SIM.timeToSessionStart), How I use it to make a simple app that let car auto gear up when race starts? anyone can teach me how to use both function?
Last edited: