HaxeFlixel / HaxeFlixel/flixel
Collision overlap flags and separation
Nobody has claimed this yet.
- Dominant language
- Haxe
- Stars
- 2.2k
- Forks
- 522
- Avg merge
- 34m
- Merged PRs (30d)
- 1
Description
I've run into an issue with the way collision flags and separation are handled.
Here's the issue:
I have a handful of objects that all have custom collision code that depends on knowing: which 'side' they are colliding with (FLOOR, CEILING, etc), AND their velocity at the time of collision.
Trying to handle this within the current logic is not working.
If I just try to do FlxG.collide with a callback: FlxG.collide(objectsA, objectsB, callback);, then when FlxObject.separate is called, before my callback, it's changing the velocity of my objects, so I can't reliably handle their collsion.
If I try to use FlxG.overlap, and use the notifier: FlxG.overlap(objectsA, objectsB, callback, notifier);
And I setup my notifier like this:
private function notifier(A:FlxObject, B:FlxObject):Bool
{
A.specialCollisionLogic();
return FlxObject.separate(A, B);
}
Then the collision flags have not been set yet, so I don't know what side is colliding...
I came up with a solution that does work, but it creates performance issues since it's checking everything twice as often:
private function notifier(A:FlxObject, B:FlxObject):Bool
{
FlxObject.updateTouchingFlags(A, B);
A.specialCollisionLogic();
return FlxObject.separate(A, B);
}
This does pretty much exactly what I want it to do, except it's basically calling computeOverlapX and computeOverlapY twice per update, and it's killing my performance.
So, I think there needs to be someway to easily insert some kind of behavior into the FlxObject.separate routine in order to sort of 'pre-collide' after the collision flags have been set.
I'm not sure what the best implementation would be... maybe add a new parameter for a function to call in separate? Ideas?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing FlxG.collide and FlxG.overlap into FlxObject.separate, updateTouchingFlags, computeOverlapX, and computeOverlapY. Determine how a pre-collision callback could observe collision flags and original velocity without repeating overlap calculations. Done means custom collision behavior can run at that point without the reported performance cost.
Written by the indexing model from the issue text.
Assessment
- Domain
- game-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100