interpolateBetween
Client-side
Server-side
Shared
This page is incomplete! Help wanted!
Please finish this page using the corresponding Old Wiki article.
Go to Contribution guidelines for more information.
Interpolates a 3D Vector between a source value and a target value using either linear interpolation or any other easing function. It can also be used to interpolate 2D vectors or scalars by only setting some of the x, y, z values and putting 0 to the others.
Syntax
interpolateBetween ( )Code Examples
server
This clientside example uses interpolateBetween to create position and color interpolation(with effect) on a marker. The command to test it is "/marker". The position is interpolated with "OutBounce" as strEasingType to make the marker bounce off the ground and "Linear" interpolation for the color.
local g_Marker = niladdCommandHandler("marker",function () if g_Marker then return end
local x, y, z = getElementPosition(getLocalPlayer()) z = z - 1
g_Marker = {} g_Marker.startPos = {x, y, z + 5} g_Marker.startTime = getTickCount() g_Marker.startColor = {255, 0, 0, 0} g_Marker.endPos = {x, y, z} g_Marker.endTime = g_Marker.startTime + 2000 g_Marker.endColor = {0, 0, 255, 255}
local x, y, z = unpack(g_Marker.startPos) local r, g, b, a = unpack(g_Marker.startColor) g_Marker.marker = createMarker(x, y, z, "cylinder", 1, 255, r, g, b, a)
addEventHandler("onClientRender", getRootElement(), popMarkerUp)end)
function popMarkerUp() local now = getTickCount() local elapsedTime = now - g_Marker.startTime local duration = g_Marker.endTime - g_Marker.startTime local progress = elapsedTime / duration
local x1, y1, z1 = unpack(g_Marker.startPos) local x2, y2, z2 = unpack(g_Marker.endPos) local x, y, z = interpolateBetween ( x1, y1, z1, x2, y2, z2, progress, "OutBounce")
setElementPosition(g_Marker.marker, x, y, z)
local r1, g1, b1, a1 = unpack(g_Marker.startColor) local r2, g2, b2, a2 = unpack(g_Marker.endColor) local r, g, b = interpolateBetween ( r1, g1, b1, r2, g2, b2, progress, "Linear") local a = interpolateBetween ( a1, 0, 0, a2, 0, 0, progress, "Linear")
setMarkerColor(g_Marker.marker , r, g, b, a)
if now >= g_Marker.endTime then removeEventHandler("onClientRender", getRootElement(), popMarkerUp) setTimer( function () destroyElement(g_Marker.marker) g_Marker = nil end, 3000, 1) endendSee Also
Utility Functions
- addDebugHook
- bitAnd
- bitArShift
- bitExtract
- bitLRotate
- bitLShift
- bitNot
- bitOr
- bitReplace
- bitRRotate
- bitRShift
- bitTest
- bitXor
- createTrayNotification
- debugSleep
- decodeString
- deref
- downloadFile
- encodeString
- fromJSON
- generateKeyPair
- getColorFromString
- getDevelopmentMode
- getDistanceBetweenPoints2D
- getDistanceBetweenPoints3D
- getEasingValue
- getFPSLimit
- getKeyboardLayout
- getLocalization
- getNetworkStats
- getNetworkUsageData
- getPerformanceStats
- getProcessMemoryStats
- getRealTime
- getServerIp
- getTickCount
- getTimerDetails
- getTimers
- gettok
- getUserdataType
- getVersion
- hash
- inspect
- interpolateBetween
- iprint
- isOOPEnabled
- isShowCollisionsEnabled
- isShowSoundEnabled
- isTimer
- isTimerPaused
- isTransferBoxAlwaysVisible
- isTransferBoxVisible
- isTrayNotificationEnabled
- killTimer
- md5
- passwordHash
- passwordVerify
- pregFind
- pregMatch
- pregReplace
- ref
- removeDebugHook
- resetTimer
- setClipboard
- setDevelopmentMode
- setFPSLimit
- setTimer
- setTimerPaused
- setTransferBoxVisible
- setWindowFlashing
- sha256
- showCol
- showSound
- split
- teaDecode
- teaEncode
- tocolor
- toJSON
- utfChar
- utfCode
- utfLen
- utfSeek
- utfSub