Help with coding A.I

Can someone help me with A.I.? I recently published a slither .io WIP, and I want to know how to code the A.I. of the other snakes. (I forget that they automatically turn it into a link whoops) I need replies not likes.

12 Likes

Could I have a link to the project?


Also could a leader make this a new topic?

6 Likes

This category is the closest to your question as I could find, let me know if you think it should go somewhere else

4 Likes

Well, maybe a following code? I’m not exactly sure how to make one though

3 Likes

I want it to react to being circled, and I want it to turn around when you get in front of it’s face. Other than that I just want it to act like a normal snake.

3 Likes

Do you want multiple snakes or only one and the player? How many is the most you’d want to have?

5 Likes

Is there a way to tell if they are being circled?

2 Likes

3 that’s what I’m going for anyway.

2 Likes

Ehh, I gotta think about that.

2 Likes

Let’s see what I can do

3 Likes

So 3 enemy snakes? In that case, it would make the most sense to have each of them be its own object, and just have them all have the same custom rule. Do you also want them to avoid each other?

Maybe you could try each snake setting some variables to its x position, y position, and rotation, then in the custom rule for all snakes (including the player) have it figure out if continuing in that direction from that position would make it collide with any of the object’s clones. Maybe also include a check for distance to the snake currently asking. Try to do this every frame, or if you want to make it easier every 3 frames, but each snake gets a frame to itself.
So it’d go

Frame 1. Snake #1 figures out if it’ll collide
Frame 2. Snake #2 figures out if it’ll collide
Frame 3. Snake #3
Frame 4. Snake #1
Etc.

11 Likes

Ok! I’ll try that ASAP.

2 Likes

Ok
So
This happened
And I don’t know why.
It should work.
But it doesn’t.
Help
Snake 2
Is being annoying.

3 Likes

The repeat forever with bring to front isn’t the best way to do that. Maybe consider using the set z index block if you can, or if it is out of beta before you finish this project.


Why does text 6 (:eyes:) repeat forever flip but in a check once if? Is this on purpose?

How is it being annoying? I don’t see anything anywhere that would make it turn if that’s what you want.

4 Likes

I was trying to make the eye look in the direction of the players finger. But then it just flipped infinitely and it looked sort of like it was facing Foreward.

The enemy doesn’t start with any length. And I’ve checked the code and I think it should work…

2 Likes

Yes, you have it doing basically repeat forever flip if last touch x is any number.
last touch x will always either be >= any number at all or < any number at all, and those are the conditions for the check if else you have for flipping. You’ll need to add a variable to save if the eyes are flipped and then flip based off of that and what you currently have.

3 Likes

Also, the enemy snake should start with some length instead of just being a head.
But I’ve double checked the code, and it should be happening, but it’s not…

1 Like

You have it wait self length which for clones is 0. Use original object instead.


I had a similar problem in one of my projects and it took me hours to figure out. :rofl:

3 Likes

wow, oops
how did i not see that *facepalm

2 Likes

It took me ten minutes and I only did it so quickly because you used an iPad variable for the player snake.


Be glad it wasn’t in there for literal months.

5 Likes