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

From The Official Visionaire Studio: Adventure Game Engine Wiki
Line 10: Line 10:
  
  
== Tutorial ==
+
== Tutorial #1: Single Blink ==
1. 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>
 
if math.random(20) < 13 then
 
if math.random(20) < 13 then
Line 19: Line 19:
 
end
 
end
 
</syntaxhighlight>
 
</syntaxhighlight>
... Why have I used these these values for the AnimationLastFrame value? Well, it's because my regular idle animation is 16 frames in total & the blink frames I attached to the end of the regular idle animation consisted of 5 frames making a grand total of 21 frames. Now the idea behind this is that we are querying the math.random value to see if we should play up to frame 16 or play the entire animation, thus depending on the value returned by math.random, our character either blinks or it does not on each animation loop.
+
"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.
  
Quick note: in the second screenshot below I have actually gone a step further as I have attached some extra blink animation frames to allow the character to blink once, twice or not at all as I believe it furthers enhances the dynamic of the character in general.
+
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.
  
[[File:blink_screen_code.png|400px]] [[File:blink_screen_code_(2).png|400px]]
+
Pretty straightforward, no?
  
2. Next thing you want to do is create a button inside of one of your interfaces & set the '''button type''' to '''action area'''.
+
{| class="ts"
 +
|-
 +
| ''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.''
 +
|}
  
[[File:Hotspot 002.png|800px]]
+
[[File:blink_screen_code.png|800px]]
  
3. Create your hotspot animations inside of this button & adjust properties settings for each animation to suit.
 
  
[[File:Hotspot 003.png|400px]] [[File:Hotspot 004.png|400px]]
+
== 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.''
  
4. Next you need to assign your hotspot animations to each of your '''scene objects''' & position them on the screen via the '''effects''' tab.
+
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>
 +
blink = math.random()
  
[[File:Hotspot 005.png|800px]]
+
if blink < 40 then
 
+
ActiveAnimations["animation_name"].AnimationLastFrame = 16 -- no blink
5. Now you need to go to '''game tab > key actions''' to sort out the key inputs that will toggle the hotspots animations on/off.<br/>
+
elseif blink >= 40 and < 50 then
6. Create a '''space''' key action & inside of this create a '''scene > fade "snoop" animations in''' action part.<br/>
+
ActiveAnimations["animation_name"].AnimationLastFrame = 21 -- single blink
 
+
else
[[File:Hotspot 006.png|800px]]
+
ActiveAnimations["animation_name"].AnimationLastFrame = 27 -- double blink
 
+
end
7. Create a '''space (released)''' key action & inside of this create a '''scene > fade "snoop" animations out''' action part.<br/>
+
</syntaxhighlight>
 
+
... 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:Hotspot 007.png|800px]]
 
 
 
8. Now rinse & repeat the process for all the other scene objects that you want to show hotspot animations for.
 
 
 
[[File:jacob_blink_gif.gif|500px]]
 
  
 +
[[File:blink_screen_code_(2).png|800px]]
  
 
== Resources ==
 
== Resources ==
Line 56: Line 57:
 
! style="text-align:left" | Name !! style="text-align:left" | Description
 
! style="text-align:left" | Name !! style="text-align:left" | Description
 
|-
 
|-
| [[media:hotspot_demo.zip|hotspot_demo.zip]] || A working .ved file, complete with resources. Check out the readme.txt file for instructions.
+
| - || N/A
 
|}{{toc}}
 
|}{{toc}}

Revision as of 15:14, 5 August 2016

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()

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.

Blink screen code (2).png

Resources

Name Description
- N/A