Monkey = ScriptObject()

function Monkey:Start()
    self.speed = 1.0
    self.distance = 10.0
end

function Monkey:Update(timeStep)    
    local parent = self.node:GetParent()
    local parentPos = parent:GetWorldPosition()
    local destination = parentPos + parent:GetWorldDirection() * self.distance
    local current = self.node:GetWorldPosition()

    local dir = destination - current
    if dir:Length() < 0.1 then
        self.node:SetPosition(Vector3(0, 0, 0))        
        -- New position
        parent:SetWorldPosition(Vector3(parentPos.x, math.random(0, 2) - 2, math.random(0, 2) - 2))
        -- New speed
        self.speed = 3 + math.random(0, 3)
        -- New scale
        local scale = 0.5 + math.random(0, 2)
        self.node:SetScale(Vector3(scale, scale, scale))
    else
        local x = self.speed * timeStep
        dir:Normalize()
        self.node:Translate(dir * x, TS_WORLD)
    end    
end