Zbyszeq
Zbyszeq

Reputation: 1

FlxRect.getRotatedBounds not getting hitboxes correctly?

I'm making an Undertale damage system but I just can't get it right. What is wrong in this code? blaster and soul are FlxSprites.



var point1:FlxPoint = FlxPoint.weak(blaster.x, blaster.y + 104 * blaster.scale.y);

var point2:FlxPoint = FlxPoint.weak(blaster.x + blaster.width, blaster.y + blaster.height - 140 * blaster.scale.y);

var blasterMidpoint:FlxPoint = FlxPoint.weak(blaster.getMidpoint().x, blaster.getMidpoint().y);



var soulhit1:FlxPoint = FlxPoint.weak(soul.x, soul.y);

var soulhit2:FlxPoint = FlxPoint.weak(soul.x + soul.width, soul.y + soul.height);



var hitbox:FlxRect = new FlxRect.fromTwoPoints(point1, point2);

var hitboxSoul:FlxRect = new FlxRect.fromTwoPoints(soulhit1, soulhit2);

hitbox.getRotatedBounds(blaster.angle, blasterMidpoint, hitbox);


I tried using this code with expectation of it working just fine but it happened to get the hitbox totally wrong, because it's actually way below the sprite and with angle of 0. (When I set the blaster's angle to 0 it works) When the blaster has an angle, the hitbox is even below a point as if the blaster's angle were 0

Upvotes: 0

Views: 32

Answers (1)

TheoDev
TheoDev

Reputation: 1

The hitbox positions are wrong i think

final hitboxBlasterRatio:Int = blaster.width * 0.5; //adjust
final hitboxRatio:Int = soul.width * 0.5;

final bCornerUp:FlxPoint = FlxPoint.weak(blaster.x + blaster.width / 2 - hitboxBlasterRatio / 2, blaster.y + blaster.height / 2 - hitboxBlasterRatio / 2);
final bCornerDown:FlxPoint = hitboxBlasterRatio + blaster.width / 2 + hitboxRatio / 2, blaster.y + blaster.height / 2 + hitboxBlasterRatio / 2);

final sCornerUp:FlxPoint = FlxPoint.weak(soul.x + soul.width / 2 - hitboxRatio / 2, soul.y + soul.height / 2 - hitboxRatio / 2);
final sCornerDown:FlxPoint = FlxPoint.weak(soul.x + soul.width / 2 + hitboxRatio / 2, soul.y + soul.height / 2 + hitboxRatio / 2);

final hitboxBlaster:FlxRect = new FlxRect.fromTwoPoints(bCornerUp, bCorderDown);
final hitboxSoul:FlxRect = new FlxRect.fromTwoPoints(sCornerUp, sCorderDown);

hitbox.getRotatedBounds(blaster.angle, blaster.getMidpoint(), hitboxBlaster);

try with that

Upvotes: 0

Related Questions