Skip to content

YaPendulumComponent

YaPendulumComponent controls an object in circular motion.

Functions

void PlayMoving(bool play)
Deterimines whether the object starts a circular motion. Set play to ture to start the motion.
void SetSpeed(number speed)
Sets the speed (m/s) of the circular motion.
number GetSpeed()
Gets the speed (m/s) of the circular motion.
void SetCenterPoint(float3 point)
Sets the center point of the circular motion.
float3 GetCenterPoint()
Returns the center point of the circular motion.
void SetTargetAngle(number targetPosition)
Sets the target angle to which the object moves.
number GetTargetAngle()
Gets the target angle to which the object moves.

Events

StartMoving
Triggered when the circular motion starts.
StopMoving
Triggered when the circular pauses.
FinishMoving
Triggered when the circular motion finishes.

Code samples

The following code sample demonstrates how to make an object start a circular motion.

1
2
3
4
5
6
7
8
-- Prepares the component.
local pendulum = script:GetYaComponent("YaPendulumComponent") 
-- Sets the center point to (0,0,1).
pendulum:SetCenterPoint(float3.New(0,0,1))
-- Sets the target angle to 1080 degrees.
pendulum:SetTargetAngle(1080) 
-- Starts the circular motion.
pendulum:PlayMoving(true) 

The following code samples demonstrate how an object sends an event which makes another object start a circular motion.

Sending an event.

1
2
3
4
5
6
7
8
9
-- Prepares the component.
local _trigger = script:GetYaComponent("YaPhysicsMsg")
local function Trigger(t)
    -- Executes the TriggerRotate event.
    CustomEvents:Emit("TriggerRotate" , 1) 
end

-- Adds the CharacterHit event.
EventHelper.AddListener(_trigger , "CharacterHit" ,Trigger ) 

Receiving the event.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
function Rotate(num)
    if num == 1 then
    -- Prepares the component.
    local pendulum = script:GetYaComponent("YaPendulumComponent")
    -- Starts the circular motion.
    pendulum:PlayMoving(true) 
    end
end

-- Adds the custom event from ``TriggerRotate``.
EventHelper.AddListener(CustomEvents,"TriggerRotate" ,Rotate)