#Snake Movement Grid
1 messages · Page 1 of 1 (latest)
@stable oracle this the right one?
i dont think i can find my older code.. but i can def fix up an example real quick.. as i said earlier im really really bad with grids and creating them via forloops
the logic gets me everytime once it gets more advanced than actually spawning the gridtiles
I got an idea for this
shoot
And then every time the snake moves you have a script that spawns/kills the tiles
Yes
ahh thats pretty clever
Oh yea?
ya, thast what i kiinda thought at first.. what if it zig zagged?
Must go script for fake internet points... brb
the values { length = 3, minX = 1, maxX = 3, minY = 1, minY = 3 } has 8 possible states
like if the snake did this ^
or a spiral
i seem to believe it would be overly complicated for to know using a single x,y vec2
if you only consider the boundaries, a snake spiraling into itself wouldn't even store the head
Oh no i was just talking about the tile spawn system
using a queue is just very simple and straightforward
i couldnt find that project chris.. i think i deleted it.. imma start a new one here in a minute
this is what imma try to do
altho ive never used a queue other than for task management
oh like showing where the snake is?
still would have 4 possible states for this scenario
Showing the furthest point of the snake so you can spawn more tiles infront of it
i just bought some graphing paper! what a wonderful suprise.. i can use that today in my research
wasn't even sure what i was gonna do with it 😅
Do people besides me actually use paper for coding?
i use paper all the time
only when i have it on hand
i drew so many scenarios for figuring out background tiling lol
its also common for me to sketch out ideas
to feed to AI.. to get a better image.. that i can use as reference to model
Ai did not do justice lol
lol.. ya i know 😦 it was a bit disappointing
but the best i could get it to do
the first iteration was even worse
i mean.. its a decent thumbnail i guess..
alright lemme write up a script
weird path though
but if i feed the AI my own sketches.. i kinda eliminate some of the chances that i get regurgitated artwork from someone else
altho idk what queues are so im gonna use arrays
its basically that ^
(the jank strikes again)
same thing
oh i see
it's a layer right above a list
array - sequence of elements
list/vector - sequence of elements with dynamic length
queue/stack - sequence of elements with dynamic length and specified operations
what namespace does queue use again?
the same as list
is it the same
ok
alrighty!! nose to the grindstone!!
i shall update with my first attempt
thanks for the 1on1 guys
and for movement i probably also need like a stepper..
move once / so and so frames
so i get that one step at a time kinda feeling
could u send me the unity documentation page, cant find it for some reason
it's not a unity thing, it's a c# thing
a list (at the very basic level) defines retrieving, setting, adding, and removing at a certain index
a stack defines adding, retreiving, and removing only at the end
a queue defines adding only at the end, and retrieving and removing only at the start
heres a doc page about queues
thats what i ment sorry
this is a single specific use of queues, not a very good resource for queues in general
ya im on it
the better resource...
Represents a first-in, first-out collection of objects.
this is, at its core, what a queue is
- it's a collection
- it holds objects
- it defines
inandoutoperations - the first thing you
inis the first thing you get fromout
snake movement has been on my todo list for years now.. it'd be great to finally prototype it out
oh a question for u chris..
when u do grids are they power of 2?
theres another link to my ever growing pile of links
or do u do odd number to have a center row
i.. didn't put any thought into it
ive tried both and i honestly cant tell which is the preferred method
i just did 10x10 and called it a day
okay.. sounds good to me 👍
it doesn't really matter for a for-fun project anyways
also this is kinda funny...
very disappointed my search filter extension stopped working
what software are we lookin at?
google search engine
ohh.. super minimilistic
what browser doesn't look like this
alright..
Step1. Create a Grid (i shall return)
-# narrator: he never returned
with adblocker mine would proabably look similar
nah, wont take me 10 minutes to make a grid
-# little did he know, he was right - it took him 10 hours instead
i knew it 🤣
lmao
-# predictability++
-# and he was never seen again
soo i guess next i should make the head of the snake.. and center it.. once we press a directional key.. the head begins to travel and the initial segments appear until the head moves (segment number) from the origin.. then the tail will begin to move..
phew... getting the snake to spawn in slowly until it reaches its full starting length
and then making it work from the queue from then on was a pita
ooh nice
i kept getting gaps and stuff on the 3rd move.. (finally i realized i had to keep track of every position of every segment)
atleast to grow it the way i wanted.. and then i realized i could give quick inputs between steps to get it to reverse on itself
so i added a little input buffer.. (just 1 input per step)
and that got it where it wont reverse on itself 💪
now.. i gotta add apples and see if it grows correctly
aye, the starting logic works
the entire "Input buffer b/c of the step movement" is a good learning lesson ngl
i just made it ignore going the opposite way of the current direction lol
could u show me how you used Queue? kinda having trouble using it
i actually couldnt get it to work the way i wanted to with a queue.. i did orignally but to build the snake i wanted it to start with 1 piece. then 2 piece, then 3 piece.. the queue method i was using needed all pieces to be there at teh get go.. so instead
** i used two lists ** - one for position history and one for snake segments
im just keeping track of each pieces position..
only the head is actually moving
and then the rest of the pieces follow
basically like here's the snakes path -- now every piece follow the guy in front
private List<GameObject> snakePieces = new List<GameObject>();
private List<Vector2Int> positionHistory = new List<Vector2Int>();```
```cs
for (int i = 0; i < snakePieces.Count; i++)
{
if (i < positionHistory.Count && i < startingLength)
{
// Move piece to the position in history
Vector3 worldPos = grid.GetWorldPosition(positionHistory[i].x, positionHistory[i].y);
snakePieces[i].transform.position = worldPos;
snakePieces[i].SetActive(true);
}
else
{
snakePieces[i].SetActive(false); // Hide unused pieces
}
}```
i first check if the head is moving to a valid position.. if it is i move the head.. and then the next segment (2nd) piece then goes to where the head was, and the (3rd) piece goes where that piece was
check out the inspector..segment0 is the head.. so it goes to element 0 in the history (most recent move).. then 1-1, 2-2, 3-3 etc.. the reason i have 10 positions is because my snake can grow to 10 segments... so i need to track all 10 recent locations to keep the snake updated properly
imma work out the queue thing a bit later.. (its probably the proper way to do it)