Custom Maps & Logic
  • Custom Map Tutorial
    • Custom Map Introduction
    • Your first map
    • Map Navigation
    • Object Selection
    • Object Positioning
    • Object Attributes
    • Shortcuts and Macros
    • Editor Settings
    • Built-in Components Common Errors
    • Map Performance
    • Custom Assets
      • Your first Asset Bundle
      • Asset Bundles in Map Editor
      • Asset Bundles in Game
      • Adding to Asset Bundles
      • Asset Bundle naming
  • Custom Logic Tutorial
    • Custom Logic Introduction
    • Your first script
    • Variables
    • Types
    • Variable Inspector
    • Expressions
    • Conditionals
    • Loops
    • Functions
    • Coroutines
    • Classes
    • Static Classes
    • Components
    • Extensions
    • Cutscenes
    • Static Objects
    • Networking
    • Commenting
  • Reference
    • Static Classes
      • Game
      • Network
      • Map
      • UI
      • Time
      • Convert
      • String
      • Input
      • Math
      • Random
      • Cutscene
      • Camera
      • RoomData
      • PersistentData
      • Json
      • Physics
    • Objects
      • Component
      • Object
      • Character
      • Human
      • Titan
      • Shifter
      • MapObject
      • Transform
      • Player
      • NetworkView
      • Color
      • Vector3
      • Quaternion
      • Dict
      • List
      • Range
      • LineCastHitResult
      • MapTargetable
      • Random
    • Callbacks
      • Main
      • Components
  • Examples
    • Gamemodes
      • Survive
      • Waves
      • Endless
      • Racing
      • Blade PVP
      • Thunderspear PVP
      • Titan Explode
      • Cranked
      • More Examples
    • Components
      • SupplyStation
      • Daylight
      • PointLight
      • Rigidbody
      • NavMeshObstacle
      • Cannon
      • Dummy
      • Wagon
      • Tag
      • KillRegion
      • DamageRegion
      • MovePingPong
      • RacingCheckpointRegion
      • RacingFinishRegion
      • TeleportRegion
      • Animal
      • SignalMover
      • SignalSender
      • More Examples
Powered by GitBook
On this page
  1. Examples
  2. Components

MovePingPong

The MovePingPong component moves an object between two positions. If RelativePositions is false, it will use the world position instead of the local position.

component MovePingPong
{
    RelativePositions = true;
    StartPosition = Vector3(0, 0, 0);
    EndPosition = Vector3(0, 0, 0);
    Speed = 10.0;
    PauseTime = 0.0;
    _currentProgress = 0.0;
    _backwards = false;
    _pauseTimeLeft = 0.0;

    function Init()
    {
        if (self.RelativePositions)
        {
            self.StartPosition = self.MapObject.Position + self.StartPosition;
            self.EndPosition = self.MapObject.Position + self.EndPosition;
        }

        distance = Vector3.Distance(self.StartPosition, self.EndPosition);
        self._step = 1.0;
        if (distance > 0)
        {
            self._step = self.Speed / distance;
        }
    }

    function OnTick()
    {
        if (self._pauseTimeLeft > 0)
        {
            self._pauseTimeLeft = self._pauseTimeLeft - Time.TickTime;
            return;
        }
        if (self._backwards)
        {
            self._currentProgress = self._currentProgress - Time.TickTime * self._step;
            if (self._currentProgress <= 0.0)
            {
                self._currentProgress = 0.0;
                self._backwards = false;
                self._pauseTimeLeft = self.PauseTime;
            }
            self.MapObject.Position = Vector3.Lerp(self.StartPosition, self.EndPosition, self._currentProgress);
        }
        else
        {
            self._currentProgress = self._currentProgress + Time.TickTime * self._step;
            if (self._currentProgress >= 1.0)
            {
                self._currentProgress = 1.0;
                self._backwards = true;
                self._pauseTimeLeft = self.PauseTime;
            }
            self.MapObject.Position = Vector3.Lerp(self.StartPosition, self.EndPosition, self._currentProgress);
        }
    }
}
PreviousDamageRegionNextRacingCheckpointRegion

Last updated 9 months ago