Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Tutorial:Blinking: Difference between revisions

From FiguraMC
Created page with "== How to blink == First, you need to have eyes to scale. I'm gonna store them in a variable for easier accessing, as well as how fast I want to blink (in ticks). Your path will be different <syntaxHighlight lang="lua"> local eyes = models.model.root.UpperBody.TheHead.Eyes local BLINK_RATE = 4 * 20 -- 4 Seconds </syntaxHighlight> Next, I want to create a <code>TICK</code> event to set when my eyes blink, as well as 5 variables: tick, oldScale, newScale, oldPos, and new..."
 
No edit summary
Line 1: Line 1:
== How to blink ==
== How to blink ==
First, you need to have eyes to scale. I'm gonna store them in a variable for easier accessing, as well as how fast I want to blink (in ticks). Your path will be different
First, you need to have eyes to scale. I'm gonna store them in a variable for easier accessing, as well as how fast I want to blink (in ticks). Your path will be different
 
[[File:EyeGroup.png|thumb]]
<syntaxHighlight lang="lua">
<syntaxHighlight lang="lua">
local eyes = models.model.root.UpperBody.TheHead.Eyes
local eyes = models.model.root.UpperBody.TheHead.Eyes

Revision as of 23:23, 26 September 2024

How to blink

First, you need to have eyes to scale. I'm gonna store them in a variable for easier accessing, as well as how fast I want to blink (in ticks). Your path will be different

local eyes = models.model.root.UpperBody.TheHead.Eyes
local BLINK_RATE = 4 * 20 -- 4 Seconds

Next, I want to create a TICK event to set when my eyes blink, as well as 5 variables: tick, oldScale, newScale, oldPos, and newPos, initialized as shown

local oldScale = vec(1, 1, 1)
local newScale = vec(1, 1, 1)
local oldPos = vec(0, 0, 0)
local newPos = vec(0, 0, 0)

local tick = 0
function events.TICK()
  oldPos = newPos
  oldScale = newScale
  tick = tick + 1

  if tick % BLINK_RATE == 0 then
    newScale = vec(1, 0, 1)
    newPos = vec(0, -1 --[[Half the height of your eyes]], 0)
  else
    newScale = vec(1, 1, 1)
    newPos = vec(0, 0, 0)
  end
end

Finally, you want to create a RENDER event to make the blinking smooth

function events.RENDER(delta)
  local scale = math.lerp(oldScale, newScale, delta)
  local pos = math.lerp(oldPos, newPos, delta)

  eyes:setPos(pos):setScale(scale)
end