Difference between revisions of "AlignChar (CMS)"
From The Official Visionaire Studio: Adventure Game Engine Wiki
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | {| class=" | + | {| class="ts" style="width:100%" |
|- | |- | ||
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By | ! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By | ||
Line 7: | Line 7: | ||
This small function allows you to quickly align a character to another character. | This small function allows you to quickly align a character to another character. | ||
− | + | {| class="toccolours mw-collapsible mw-collapsed ts" | |
− | + | |- | |
− | + | ! Additional Info | |
− | + | |- | |
− | + | | Alignment is based on character center which is usually set near the feet. | |
− | + | |- | |
+ | | There is no simple method for obtaining the top (y) pixel coordinate of the currently active character animation. | ||
+ | |} | ||
== Instructions == | == Instructions == | ||
Line 22: | Line 24: | ||
2b. To align a specific character to another character... | 2b. To align a specific character to another character... | ||
<syntaxhighlight> | <syntaxhighlight> | ||
− | + | alignChar("character_name", "character_name") | |
</syntaxhighlight> | </syntaxhighlight> | ||
2c. To align a specific character to current character... | 2c. To align a specific character to current character... | ||
<syntaxhighlight> | <syntaxhighlight> | ||
− | + | alignChar("character_name", "") | |
</syntaxhighlight> | </syntaxhighlight> | ||
Line 50: | Line 52: | ||
== Syntax Breakdown == | == Syntax Breakdown == | ||
− | {| class=" | + | {| class="ts" style="width:100%" |
|- | |- | ||
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left;width:80%" | Description | ! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left;width:80%" | Description |
Revision as of 20:40, 12 July 2015
Name | Type | By |
---|---|---|
alignChar("c", "t") | Definition | AFRLme |
This small function allows you to quickly align a character to another character.
Additional Info |
---|
Alignment is based on character center which is usually set near the feet. |
There is no simple method for obtaining the top (y) pixel coordinate of the currently active character animation. |
Instructions
1. Add the main script to the Visionaire Studio Script Editor & set the script as a definition script.
2a. To align current character to another character...
alignChar("", "character_name")
2b. To align a specific character to another character...
alignChar("character_name", "character_name")
2c. To align a specific character to current character...
alignChar("character_name", "")
Main Script
function alignChar(c, t)
if c == "" then c = game:getLink(VGameCurrentCharacter) else c = getObject("Characters[" .. c .. "]") end
if t == "" then t = game:getLink(VGameCurrentCharacter) else t = getObject("Characters[" .. t .. "]") end
-- + --
local p1 = c:getPoint(VCharacterPosition)
local p2 = t:getPoint(VCharacterPosition)
-- + --
local ax, ay
ay = p1.y - p2.y
ax = p2.x - p1.x
-- + --
local angle = math.deg( math.atan2(ay, ax) )
if angle < 0 then angle = 360 + angle end
-- + --
c:setValue(VCharacterDirection, angle)
end
Syntax Breakdown
Name | Type | Description |
---|---|---|
c | "string" | This should be a "string" value containing the name of the character you want to affect; if string is empty it will default to current character. |
t | "string" | This should be a "string" value containing the name of the character you want to align to; if string is empty it will default to current character. |