-- constants
------------------------------------------------------------------
-- force applied to noodle when clicking
local CLICK_FORCE = Vector3.new( 0, -1200, 0 )
local SCALE = settings.scale * 0.114

-- options
------------------------------------------------------------------
ym.setCullMode( true )
ym.setZBuffer( true )
ym.setGlobalLight( Vector3.new( 0, 0.8, 0 ) )
ym.setGravity( Vector3.new( 0, 90, 0 ) )

-- state
------------------------------------------------------------------
-- determines if click force should be active
local clickForceActive = false

-- noodle setup
------------------------------------------------------------------
-- load noodle model
local noodle = Node.load('Noodle.glb')

-- apply skin
local bitmap = Bitmap.new('Skins/' .. settings.skin .. '.png')
local texture = Texture.new(bitmap)
noodle.mesh.material.texture = texture

-- apply scale
noodle.scale = Vector3.new(SCALE)

-- orient like a cursor
noodle.rotation:rotateZ( -math.pi * 0.38 )

-- autobuild physics and apply jiggle
noodle.physics:build({ dynamic = false, rig = true, jiggle = settings.jiggle })

-- spawn it
noodle:spawn()

-- events
------------------------------------------------------------------
-- step each frame and update noodle position to match cursor position
function step(deltaTime)
    noodle.position = Vector3.new( ym.getCursorPosition(), 500 )
    if clickForceActive then
        noodle.physics:addForce(CLICK_FORCE)
    end
end

-- while left mouse button down apply activate click force
function button(id, down)
	if id == buttons.mouse_left or id == buttons.mouse_right then
        clickForceActive = down
	end
end

-- when stopping this cursor, stop activate click force
function stop()
    clickForceActive = false
end
