This small function allows you to quickly align a character to another character.
|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.|
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...
2b. To align a specific character to another character...
2c. To align a specific character to current character...
function alignChar(c, t) if c == nil then c = game.CurrentCharacter else c = Characters[c] end -- store character or current character if t == nil then t = game.CurrentCharacter else t = Characters[t] end -- store character or current character -- + -- local p1 = c.Position -- store characters position local p2 = t.Position -- store target characters position -- + -- local ax, ay ax = p2.x - p1.x -- calculate x destination coordinate ay = p1.y - p2.y -- calculate y destination coordinate -- + -- local angle = math.deg( math.atan(ay, ax) ) -- calculate angle if angle < 0 then angle = 360 + angle end -- some fallback? I don't remember why I wrote it -- + -- c.Direction = angle -- update specified characters direction end
|c||"string" or nil||This should be a "string" value containing the name of the character you want to affect, or nil if you want to link to the current character.|
|t||"string" or nil||This should be a "string" value containing the name of the character you want to align to, or nil if you want to link to the current character.|