Difference between revisions of "AlignObj (CMS)"

From The Official Visionaire Studio: Adventure Game Engine Wiki
m (Text replacement - "wikitable" to "ts")
(One intermediate revision by the same user not shown)
Line 7: Line 7:
  
 
This small function allows you to quickly align a character to an object.
 
This small function allows you to quickly align a character to an object.
<div class="toccolours mw-collapsible mw-collapsed tbl-ds">
+
{| class="toccolours mw-collapsible mw-collapsed ex"
<span class="bold">Additional Info</span>
+
|-
<div class="mw-collapsible-content">
+
!Additional Info
<div class="alt-bg">Alignment is based on character center which is usually set near the feet.</div>
+
|-
<div>There is no simple method for obtaining the top (y) pixel coordinate of the currently active character animation.</div>
+
| Alignment is based on character center which is usually set near the feet.
<div class="alt-bg">&nbsp;</div>
+
|-
<div>Alignment to the object is based on the object interaction position; I may change this to object offset position in the future.</div>
+
| There is no simple method for obtaining the top (y) pixel coordinate of the currently active character animation.
</div></div>
+
|-
 +
| &nbsp;
 +
|-
 +
| Alignment to the object is based on the object interaction position; I may change this to object offset position in the future.
 +
|}
  
  

Revision as of 19:56, 25 September 2014

Name Type By
alignObj("c", "t") Definition AFRLme

This small function allows you to quickly align a character to an object.

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.
 
Alignment to the object is based on the object interaction position; I may change this to object offset position in the future.


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 an object...

alignObj("", "object_name")

2b. To align a specific character to an object...

alignObj("character_name", "object_name")

Main Script

function alignObj(c, t)
 if c == "" then c = game:getLink(VGameCurrentCharacter) else c = getObject("Characters[" .. c .. "]") end
 t = getObject("Game.GameCurrentScene.SceneObjects[" .. t .. "]")
 -- + --
 local p1 = c:getPoint(VCharacterPosition)
 local p2 = t:getPoint(VObjectPosition)
 -- + --
 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 object you want to align to.