Created
February 26, 2024 21:00
-
-
Save poisonHornGames/792a6d42a63419a335036f74dee541bf to your computer and use it in GitHub Desktop.
Flixel LookAt Function
This file contains hidden or 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
| import flixel.FlxSprite; | |
| import flixel.math.FlxPoint; | |
| /** | |
| * Simple LookAt function | |
| * | |
| * Takes a source sprite, which is the sprite that will rotate towards the target point | |
| */ | |
| class Utils | |
| { | |
| public static function LookAt(source:FlxSprite, target:FlxPoint) | |
| { | |
| var DeltaX:Float; | |
| var DeltaY:Float; | |
| var result:Float; | |
| DeltaX = source.x - target.x; | |
| DeltaY = source.y - target.y; | |
| result = (Math.atan2(-DeltaX, DeltaY) * 180.00000) / 3.141592; | |
| source.angle = result; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment