Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+1)

Thanks for checking out my game!

 I never thought of using rigidbodies that way, im sure it made the collisions easy to add.

My snake is completely transform based, and is attached together using a bit of math.

Similar to you, i have a bunch of segments, the head, middle segments, and the tail. I put all of them in a class

Ill try to explain as best as i can.

Basically, its a big chain of connected points. Each point is confined to another via a distance constraint (takes the distance between one point and another, and normalizes it). If one point moves, the rest follow it. Its pretty simple on its own, but i also managed to add angle constraints for each individual segment, so the snake cant turn on to itself too weirdly. 

And thats pretty much the concept, all i have to do is move the head and the rest of the body follows smoothly. It is a bit more complicated in code, especially with the angle constraints, though.

One problem with transforms, i couldnt get collision physics to work, so i just changed the angle when the snake hits a wall.

Thanks for sharing :) nice to see how other people do it

(1 edit)

I think it might have been fine if you only added a rbody to the head for collision? But i'm geussing you tried that. Alternatively as long as you snake has colliders you could give the walls rbodies instead.

Also what your doing kinda sounds like re-inventing hinge joints, but doing it yourself does make it super flexible 

Either way cool approach and thanks for letting me know, it seems to work well for the more fast paced nature of your game