Created
October 4, 2022 08:01
-
-
Save synctam/d938cb30f5248baceba51986829bd130 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
■ Vector2D 版の Normalized 関数 | |
AGKには、ベクトルの正規化関数がないみたいなので、Vector2D版のNormalized関数作りました。 | |
これを利用すると、縦・横・斜めの移動速度を一定にすることができます。 | |
// | |
// Vector2d型 | |
// | |
Type Vector2d | |
x as float | |
y as float | |
EndType | |
// | |
// Vector2dNormalized | |
// 引数で受け取った Vector2d 型のデータを正規化した値に変換する。 | |
// (斜め移動で速度が速くならないようにするときに便利) | |
// | |
// 引数 | |
// vec: 変換したいVector2d型 | |
// | |
// 戻り値:なし | |
// | |
// 参考資料: | |
// 「Normalize a vector - GameCreators Forum」 | |
// https://forum.thegamecreators.com/thread/226079 | |
// | |
Function Vector2dNormalized( vec ref as Vector2D ) | |
local length as float | |
length = Sqrt( vec.x * vec.x + vec.y * vec.y ) | |
vec.x = vec.x / Length | |
vec.y = vec.y / Length | |
EndFunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment