Skip to content

Instantly share code, notes, and snippets.

@poisonHornGames
Created February 26, 2024 21:00
Show Gist options
  • Select an option

  • Save poisonHornGames/792a6d42a63419a335036f74dee541bf to your computer and use it in GitHub Desktop.

Select an option

Save poisonHornGames/792a6d42a63419a335036f74dee541bf to your computer and use it in GitHub Desktop.
Flixel LookAt Function
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