Forum rules - please read before posting.

Stuck on Color Collision Detection for Weeks – Need Help!

Hello everyone, and first of all, I apologize if my request goes beyond the usual topics related to Adventure Creator. However, AC is the reason I started this journey as an indie dev, and I’m slowly trying to push myself further by implementing small scripts and additional mechanics that will eventually work on a solid AC foundation. I’ve always found a lot of help in this forum and this community, so I hope someone can guide me through this issue.

I'm trying to create a combat system based on color collisions, but I'm not a programmer—I have never written code in my life. However, I recently started trying with various AIs (ChatGPT and Copilot), and I must say that for other small scripts to improve my game, they worked quite well for me. But now, I'm stuck on this issue for weeks.

In my game, the player can draw the sprites of their own "monster" and then make them fight against pre-drawn enemies. The system is based on pixel art and colors. Basically, the player draws on a fully transparent 32x32 PNG texture, which is then overwritten and loaded into another scene where the combat takes place.

In the combat scene, I managed to create a script that generates a pixel-perfect collider around the colored pixels. Then, I added a controller that makes the sprites move toward each other and rigidbodies that make them bounce backward on each collision. For now, the basic system should work so that if the contact happens on red, it deals damage, and if it happens on blue, it blocks the damage. Unfortunately, I'm stuck on the color detection script.

I have two main problems:

1) The collisions (from what I was able to analyze) almost always happen outside the collider. As you can see in the image, there is a black pixel that is a gizmo created by a script, allowing me to visualize where the contact occurred on each sprite. But I don't know if this can be fixed or if it even matters. I mean, even if the contact happens outside the collider, I was looking for a system to detect the nearby pixels.

2) The real main issue is that I haven't been able to make the color detection script work in any way (which Copilot writes under my instructions). I tried using both raycast and a search expansion system based on radius until it finds a colored pixel, making it ignore transparent pixels. However, the color detection system often gets the color wrong, detecting the wrong color from who knows where.

I'm attaching the code here as well. I hope there is a kind soul who can help me—this is the only complex component I need to complete my game in the few free hours I have after work, hoping that one day this could become my full-time job.

I don't know if my approach is wrong and if a different method would be better to achieve what I want, or if it's just the AI failing to write functional code.

Sorry for my bad English, I'm Italian.

CODE:
https://pastebin.com/gGFTyLgR

IMAGE
https://imgur.com/a/6xomUl7

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.