GE Lua Documentation

Press F to search!

objectTeleported

Definition


-- @/lua/ge/extensions/core/camera.lua:774

-- figure out if an object has teleported, by analyzing its position and speed
-- e.g. a car that has moved 2 meters in a single frame via the insert-recovery key has been teleported
--      but a space rocket hurtling through the solar system, that has moved 5kms in the last frame, is not a teleport
local function objectTeleported(curPos, prevPos, prevVel, dt)
  -- if we have no previous data, assume this was a teleport event
  -- e.g. the object just got spawned from nowhere into existence, we interpret that as a teleport
  if not curPos or not prevPos then return true end

  -- if the object barely moved, assume it was not a teleport event
  -- e.g. when changing vehicle parts, the car will respawn "in-place"; normally a few cms or dms away. we interpret that as NOT a teleporting event
  -- e.g. we use insert-key recovery. the vehicle gets smartly placed 0.5m away to avoid spawning through a tree. this is also NOT a teleport. but if Smart recovery moves it 5 meters, then that's a teleport event
  -- e.g. a plane travelling mach 1 gets 'recovered' in place (insert key), this is also not a teleporting event
  -- if the object travels slow enough, assume it was not a teleport event
  -- e.g. if the object didn't even reaching mach 1, assume it's unlikely to have been a teleport
  -- more complex example: during a teleport, velocities might look like [10, 10, 10, 50000, 0, 0, 0]. there are two clear spikes in acceleration - two potential teleport events. however, the second potential teleport will get ignored with this check
  local teleportDist = 277 * dt
  if prevPos:distance(curPos) < math.max(1.5, teleportDist) then return false end -- in m/s, threshold to detect teleport with F7 / recovery / reset / replay seeking

  -- if the object velocity is consistent (such as, consistently extreme), assume this was not a teleport
  -- e.g. a concorde is flying at mach 2 speed. every frame might look like a teleport, but that's just a normal day of 90s transatlantic travel for bill gates
  return ((curPos - prevPos) / dt):distance(prevVel) > teleportDist
end

Callers

@/lua/ge/extensions/core/cameraModes/external.lua
  -- check if we need to reset anything (e.g. user just activated this camera, or vehicle got teleported, etc)
  if core_camera.objectTeleported(self.camPos, self.lastCamPos, self.lastCamVel, data.dt) then self:camTeleported() end -- cam teleported
  if data.teleported then self:carTeleported() end -- car teleported
  if data.teleported then self:carTeleported() end -- car teleported
  if core_camera.objectTeleported(carPos, self.lastCarPos, self.lastCarVel, data.dt) then self:carTeleported() end -- car *appears* to have teleported since the last time this camera was used
  self.lastCarPos:set(carPos)
@/lua/ge/extensions/freeroam/crashCamMode.lua

  local hasTeleported = core_camera.objectTeleported(playerPos, playerPosLast, playerVelLast, dtReal)
  if not crashCamActive then
@/lua/ge/extensions/gameplay/markerInteraction.lua
  if not timeSincePlayerTeleport then
    timeSincePlayerTeleport = core_camera.objectTeleported(updateData.camPos, lastCamPos, playerVelLast, dtReal) and 0.5
  end
@/lua/ge/extensions/core/camera.lua
    camData.vel:setScaled(1/dtSim)
    camData.teleported = objectTeleported(camData.pos, camData.prevPos, camData.prevVel, dtSim)
    if camData.teleported then