Discuss Scratch
- Koamodo975
-
1000+ posts
Enemy-to-enemy collisions
So I'm still working on that big game (for those of you who haven't seen it, it's called Drossworks) and I decided to rewrite the top-down code, because griffpatch's Zombie Cube tutorial was not working very well. Well, I finished the engine (Koa's Crisp Top-Down Scrollr) in about an hour or so and decided to try and add enemy-to-enemy collisions, since it's really annoying for all your enemies to clump up, and it works.
Pretty much.
The code I used is from ShiftClickLearn's youtube tutorial for a top-down shooter: Switch the costume to a vertical line on the right side of the hitbox, and move the enemies backwards if they touch one another while in this costume. It's… okay, but it's still kind of buggy. Enemies will get stuck in each other and glide away until they manage to untangle themselves, and they sort of bounce off each other. Got any better ways to do this?
link
Pretty much.
The code I used is from ShiftClickLearn's youtube tutorial for a top-down shooter: Switch the costume to a vertical line on the right side of the hitbox, and move the enemies backwards if they touch one another while in this costume. It's… okay, but it's still kind of buggy. Enemies will get stuck in each other and glide away until they manage to untangle themselves, and they sort of bounce off each other. Got any better ways to do this?
link
- Koamodo975
-
1000+ posts
Enemy-to-enemy collisions
Okay I just found another problem if I move so the enemies are off the screen, they can move through walls.
- Access_Granted00
-
3 posts
Enemy-to-enemy collisions
make two lists and name them clone x and clone y
then check the closest clone position for each clone
since the enemy clones are just circles you can detect collision easily
when collision detected point towards the collision and go back untill there's no collision
not the most accurate way but it works
there are advanced methods of course but this may reduce the performance which i dont really recommend if you're not planning to make a physics engine or something like that
or you can use AI swarms like in griffpathc's tutorial
then check the closest clone position for each clone
since the enemy clones are just circles you can detect collision easily
if <(istance to closest clone) < [radius]> then
collision
end
when collision detected point towards the collision and go back untill there's no collision
not the most accurate way but it works
there are advanced methods of course but this may reduce the performance which i dont really recommend if you're not planning to make a physics engine or something like that
or you can use AI swarms like in griffpathc's tutorial
Last edited by Access_Granted00 (Jan. 3, 2025 20:44:56)
- Koamodo975
-
1000+ posts
Enemy-to-enemy collisions
I mean okay but the enemy hitboxes are squares. also it looks like this'll break when there's multiple enemies touching each other at once.
Last edited by Koamodo975 (Jan. 4, 2025 10:38:01)
- Access_Granted00
-
3 posts
Enemy-to-enemy collisions
a better collision detection will cost your performance I mean okay but the enemy hitboxes are squares. also it looks like this'll break when there's multiple enemies touching each other at once.
however if you want it anyway you can check this studio for a tutorial https://scratch-mit-edu.ezproxyberklee.flo.org/studios/35458352/
- Koamodo975
-
1000+ posts
Enemy-to-enemy collisions
well uh that looks like a real frame drain. I tried to modify my early code and it works better now, but due to the stupid way I made collisions they still get stuck in walls, also they will create these weird ‘tail’ sort of things where they all just line up diagonally. it would still pretty much work for the game, but it's really annoying.a better collision detection will cost your performance I mean okay but the enemy hitboxes are squares. also it looks like this'll break when there's multiple enemies touching each other at once.
however if you want it anyway you can check this studio for a tutorial https://scratch-mit-edu.ezproxyberklee.flo.org/studios/35458352/
Last edited by Koamodo975 (Jan. 6, 2025 11:23:53)
- Koamodo975
-
1000+ posts
Enemy-to-enemy collisions
okay another thing the enemies will sometimes get into a shoving match, so they can't actually get to the character.
- GamingCat12345
-
100+ posts
Enemy-to-enemy collisions
Idea: If the clone isn't in the collision being checked but are a short distance away from it give it (but only that one clone) a temporary boundary to keep it from colliding to avoid the issue of gliding. If the clone did find a collision, then slowly move out, checking all 8 cardinal directions until it finds the closest space where it is outside collision. (Kinda like in Griffpatch's platformer tutorial)
- Koamodo975
-
1000+ posts
Enemy-to-enemy collisions
uhh this sounds kinda confusing, what do you mean a temporary boundary? Idea: If the clone isn't in the collision being checked but are a short distance away from it give it (but only that one clone) a temporary boundary to keep it from colliding to avoid the issue of gliding. If the clone did find a collision, then slowly move out, checking all 8 cardinal directions until it finds the closest space where it is outside collision. (Kinda like in Griffpatch's platformer tutorial)
- GamingCat12345
-
100+ posts
Enemy-to-enemy collisions
Have a list that is for this sprite only, than add that hitbox's position and size to the list, add remove it after some time
- Koamodo975
-
1000+ posts
Enemy-to-enemy collisions
So you're saying if there's a collision happening, but the clone isn't colliding, but it's close, keep it from colliding at all; if it IS part of the collision, it moves out in the fastest direction?
- cookieclickerer33
-
1000+ posts
Enemy-to-enemy collisions
Try not moving the clones whenever they are about to collide maybe?
Last edited by cookieclickerer33 (Jan. 14, 2025 18:23:02)
- Koamodo975
-
1000+ posts
Enemy-to-enemy collisions
That's what I've been doing with the walls, they get stuck. Try not moving the clones whenever they are about to collide maybe?