Difference between revisions of "Dynamic Character Blinking (h2)"

From The Official Visionaire Studio: Adventure Game Engine Wiki
m
 
(13 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{| class="ts" style="width:100%"
 
{| class="ts" style="width:100%"
 
|-
 
|-
! style="text-align:left" | Name !! style="text-align:left;width:10%" | By {{AFRLme_Patreon}}
+
! style="text-align:left" | Name !! style="text-align:left;width:10%" | By
 
|-
 
|-
 
| Dynamic Character Blinking (animation, Lua) || AFRLme
 
| Dynamic Character Blinking (animation, Lua) || AFRLme
 
|}
 
|}
 
  
 
This tutorial shows you how to create dynamic blinking for your characters using some if queries & a little bit of Lua script to force which animation frames should show. This tutorial only delves into the basics of adding a blinking animation to your characters idle animations, however you could quite easily use the same method to insert blink animations anywhere you like in any of your characters animations by querying which frames should be played or skipped.
 
This tutorial shows you how to create dynamic blinking for your characters using some if queries & a little bit of Lua script to force which animation frames should show. This tutorial only delves into the basics of adding a blinking animation to your characters idle animations, however you could quite easily use the same method to insert blink animations anywhere you like in any of your characters animations by querying which frames should be played or skipped.
Line 12: Line 11:
 
== Tutorial #1: Single Blink ==
 
== Tutorial #1: Single Blink ==
 
First I started off by attaching the blink animation to the end of each of the idle animations & then I edited the first frame of each of the idle animations & created an execute a script action part containing...
 
First I started off by attaching the blink animation to the end of each of the idle animations & then I edited the first frame of each of the idle animations & created an execute a script action part containing...
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
 
if math.random(20) < 13 then
 
if math.random(20) < 13 then
 
  ActiveAnimations["animation_name"].AnimationLastFrame = 16
 
  ActiveAnimations["animation_name"].AnimationLastFrame = 16
Line 33: Line 32:
  
  
== Tutorial #2: Double Blink
+
== Tutorial #2: Double Blink ==
 
Same principal as [[#Tutorial #1: Single Blink|Tutorial #1]] except this time we will be adding some additional frames to the end of the animation, so that the character blinks twice, though technically I suppose you could also use a value, force the animation to play the blink frames only & increment or decrement the value until the value = 0 then force it back to the initial animation frame - ''actually now that I think about it, this would be a much better method as you can get a lot more creative with the amount of times the character consecutively blinks, but we'll delve into that at some other point in the future.''
 
Same principal as [[#Tutorial #1: Single Blink|Tutorial #1]] except this time we will be adding some additional frames to the end of the animation, so that the character blinks twice, though technically I suppose you could also use a value, force the animation to play the blink frames only & increment or decrement the value until the value = 0 then force it back to the initial animation frame - ''actually now that I think about it, this would be a much better method as you can get a lot more creative with the amount of times the character consecutively blinks, but we'll delve into that at some other point in the future.''
  
 
Right, so again, you need to begin by attaching enough blink animation frames to the end of each of your idle animations to allow your character to be able to blink twice in a row & then what you are going to do is edit the first frame & create an execute a script action part inside of the actions area for said animation frame. It should contain something along the lines of this...
 
Right, so again, you need to begin by attaching enough blink animation frames to the end of each of your idle animations to allow your character to be able to blink twice in a row & then what you are going to do is edit the first frame & create an execute a script action part inside of the actions area for said animation frame. It should contain something along the lines of this...
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
blink = math.random()
+
blink = math.random(60)
  
 
if blink < 40 then
 
if blink < 40 then
Line 50: Line 49:
 
... again, the "animation_name" should be changed to the actual name of the animation you have added the little script to, & the AnimationLastFrame values should reflect the amount of frames you have used for idle, single blink & total. ''Remember to take into consideration that animation names are case sensitive.''
 
... again, the "animation_name" should be changed to the actual name of the animation you have added the little script to, & the AnimationLastFrame values should reflect the amount of frames you have used for idle, single blink & total. ''Remember to take into consideration that animation names are case sensitive.''
  
[[File:blink_screen_code_(2).png|800px]]
+
<html><img src="https://wiki.visionaire-tracker.net/images/3/33/Dynamic_blink_(2).gif" width="100%"/></html>
  
 
== Resources ==
 
== Resources ==

Latest revision as of 11:30, 14 May 2019

Name By
Dynamic Character Blinking (animation, Lua) AFRLme

This tutorial shows you how to create dynamic blinking for your characters using some if queries & a little bit of Lua script to force which animation frames should show. This tutorial only delves into the basics of adding a blinking animation to your characters idle animations, however you could quite easily use the same method to insert blink animations anywhere you like in any of your characters animations by querying which frames should be played or skipped.


Tutorial #1: Single Blink

First I started off by attaching the blink animation to the end of each of the idle animations & then I edited the first frame of each of the idle animations & created an execute a script action part containing...

if math.random(20) < 13 then
 ActiveAnimations["animation_name"].AnimationLastFrame = 16
else
 ActiveAnimations["animation_name"].AnimationLastFrame = 21
end

"animation_name" would be the name of the animation (I added a generic name to the code block). Also the number values are the amount of frames of the animation without & with the blink part of the animation. In this case frames 1-16 were the idle part of the animation & frames 17-21 was the blink part.

The little script above randomly generates a number between 1 & 20 & if the number is less than 13 then it will only play the idle part of the animation but if it equals 13 or more then it will play the idle part of the animation & then the blink part of the animation. This means that there is a 7 out of 20 chance that the character will blink at the end of the idle animations loop cycle.

Pretty straightforward, no?

Quick note: In Visionaire Studio we can force which animation frames of an animation can be played by defining the initial & end frame using AnimationFirstFrame & AnimationLastFrame.

Blink screen code.png


Tutorial #2: Double Blink

Same principal as Tutorial #1 except this time we will be adding some additional frames to the end of the animation, so that the character blinks twice, though technically I suppose you could also use a value, force the animation to play the blink frames only & increment or decrement the value until the value = 0 then force it back to the initial animation frame - actually now that I think about it, this would be a much better method as you can get a lot more creative with the amount of times the character consecutively blinks, but we'll delve into that at some other point in the future.

Right, so again, you need to begin by attaching enough blink animation frames to the end of each of your idle animations to allow your character to be able to blink twice in a row & then what you are going to do is edit the first frame & create an execute a script action part inside of the actions area for said animation frame. It should contain something along the lines of this...

blink = math.random(60)

if blink < 40 then
 ActiveAnimations["animation_name"].AnimationLastFrame = 16 -- no blink
elseif blink >= 40 and < 50 then
 ActiveAnimations["animation_name"].AnimationLastFrame = 21 -- single blink
else
 ActiveAnimations["animation_name"].AnimationLastFrame = 27 -- double blink
end

... again, the "animation_name" should be changed to the actual name of the animation you have added the little script to, & the AnimationLastFrame values should reflect the amount of frames you have used for idle, single blink & total. Remember to take into consideration that animation names are case sensitive.

Resources

Name Description
- N/A