- Home /
Snaking - making body parts follow each other.
Hi all, I'm creating a top-down 2d snake-like game.
Basically, the player controls the head and has to go around collecting body parts.
I've already managed to get the body part to follow the head when it gets close enough. if(Vector3.Distance(objPlayer.transform.position,transform.position)<2f) {
rigidbody.AddForce(inputMovement.normalized*moveSpeed*Time.deltaTime);
transform.position = new Vector3(transform.position.x, 0, transform.position.z);
}
But i don't know how to get other body parts to follow the collected body parts.
Basically i just need a starting point. If you could point me in the right direction, I could carry on from there.
Thanks in advance for your help. :)
Answer by uhahaha · Dec 21, 2010 at 06:11 AM
A technique would be to apply the SmoothFollow script (it's one of the Unity's camera scripts) to the object that follows preceding body part. Head <- body part1 <- body part2 <- body part3, etc.
Answer by Dracorat · Nov 02, 2013 at 05:05 PM
Having programmed this exact game years ago when the language for doing so was CBasic I can tell you that the most common way it was done was to create an array of body parts and reposition the "tail" to the new "head" at the time. This was possible because it was ASCII graphics and there was nothing more than just solid filled squared. Thus, you created the illusion of movement by only changing the position of one object.
Depending on how low-key your graphics are, you might be able to do something similar. Or anyone else who ends up seeing this answer for this problem, for that matter.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
3D snake classical movement 2 Answers
Navmesh follow and stop at a distance 2 Answers
SpriteManager 2 1 Answer
2D rigidbody movement & walls 2 Answers