0

Actually, I am creating a snake 2D game, which is something I wanted to do from long time ago. I have created the design and the snake and the food spawn work as usual, but I would like to implement a mechanic, which if the snake passes a border either top, middle, bottom, right, left the snake comes from the opposite direction. I would like to know if anyone can help me with this? Thanks! Image: https://i.stack.imgur.com/i72lG.jpg

Code for the boundaries:

public class SnakeRespawn : MonoBehaviour
{
    [SerializeField] private Transform player;
    [SerializeField] private Transform respawnPoint;
    

    void OnTriggerEnter2D(Collider2D collision)
             {
        player.transform.position = respawnPoint.transform.position;
           // if (col.gameObject.CompareTag("Player"))
            
             //   col.transform.position = respawnPoint.position;
            }
        
    }
Zoro165
  • 31
  • 6
  • Let me see if I understood your question, you want to the snake to make a smooth transition between the walls, right? like the nokia cellphone game – Luiz May 04 '21 at 12:21
  • @Luiz Yeah, you are right. :) – Zoro165 May 04 '21 at 12:22
  • there are many ways of doing it, an easy way is dividing your sanke on chunks (it will help you later when you need to growth it and for the turning right left) and teleport each chunck individually – Luiz May 04 '21 at 12:24
  • 1
    if you want a smoother transiction you will need to use a shader – Luiz May 04 '21 at 12:25
  • @Luiz I am not familiar with shader. Can you help me in how to use it properly to make it working? Thanks! :) – Zoro165 May 04 '21 at 12:42
  • @Luiz I do not tend to use the snake tail for this game. I just want that when the head moves to the right border, it comes from the left border at the same line if you know what I mean. I would need your help if is necessary. Thanks! :) – Zoro165 May 04 '21 at 13:01
  • sorry, I don't have the knowledge to help you, but if you want to do the way I said on the first comment, here's a tutorial: https://www.youtube.com/playlist?list=PLzDRvYVwl53ucaUs0YGfyyKXdgqh5OtiK maybe try it again when you are more advanced on shaders. – Luiz May 04 '21 at 14:00
  • @Luiz Alright, thank you for your help! – Zoro165 May 04 '21 at 15:28

0 Answers0