Hey there,
I currently am just making a little prototype and have set up a little 2d bullet hell much similar to undertale/deltarune.
However, I have got everything good and ready minus the actual bullets/attacks… I’m not sure how I would go about detecting when they would hit the player or how I would move them.
Would I just do the movement with a Tween and how am I supposed to detect the touching of two uis?
I have used the Ui Collision module (Because it is posted literally everywhere I look) and it is just too much of a mess around to use for myself, although I am not entirely against using it.
I’d appreciate if someone could help me out here.
Cheers.
Wrote this on the fly and didn’t have time to test it thoroughly (only did basic testing) so it might not work perfectly. Let me know if there’s any problems.
collision module script
-- AABB collision
return function collision(a: GuiObject, b: GuiObject): boolean
return
a.AbsolutePosition.X + a.AbsoluteSize.X > b.AbsolutePosition.X and
a.AbsolutePosition.X < b.AbsolutePosition.X + b.AbsoluteSize.X and
a.AbsolutePosition.Y + a.AbsoluteSize.Y > b.AbsolutePosition.Y and
a.AbsolutePosition.Y < b.AbsolutePosition.Y + b.AbsoluteSize.Y
end
example usage
local collision = require("./collision") -- replace with actual path
-- example usage
game:GetService("RunService").RenderStepped:Connect(function()
if collision(frameA, frameB) then
print("Collision detected!")
end
end)
Note that AABB collision might not be the best solution for a bullet hell, since it only really works for squares. I might be able to make a better one, I don’t know.
if you have fast moving bullets then sometimes hitboxes will pass through players, so you can also make a raycast from the bullet position to its previous position
You should probably just look into a 2D collision library like you mentioned, or don’t use Roblox. Roblox isn’t very good for 2D games in my opinion. Deltarune was made in GameMaker, but you could go with Godot, Unity, etc. I wonder if you’ll get your prototype finished before Chapter 5 releases /j
Thinking more about it, I don’t know why I wrote you an AABB collision function. That wouldn’t work well for a bullet hell, since it only works with rectangles. I think circles would probably be better.
Eh its alright I changed this around and got myself a function that basically worked with it.
The bullets I was testing were squares/rectangles so it was fine and I’m not too fussed about the shape of them, just means like a bigger hitbox and if that becomes an issue later then I’ll deal with it then.