Search Unity

Creating a bendable snake?

Discussion in '2D' started by Blitz54, May 3, 2021.

  1. Blitz54

    Blitz54

    Joined:
    Dec 20, 2020
    Posts:
    20
    I'm struggling to accomplish my goal here. What I'm looking to do, is create a snake that bends in the direction you press on the keyboard or with an anolog stick. I don't need the snake to be slithering the whole way down its body, I'm basically aiming for the whole body being straight, and when the "bend" buttons are pressed, have the snake gradually bend to a curved 90 degrees.

    I first tried with 2d spring joints and a torque force. While it kinda does what I want, I don't see it working out as I can't keep the sprite looking clean. You can clearly see the separate sections.

    I was trying to use the Sprite Shape Profile, and while its closer to what I'm looking for, I can't figure out how to use an "Open Shape" profile. Im using unity 2020, and if I go to create>2d>Sprite Shape Profile, that's all I get. I don't get the option to use an open shape or closed shape.

    Any ideas on how I can get this to work? Thanks.
     
  2. Blitz54

    Blitz54

    Joined:
    Dec 20, 2020
    Posts:
    20
    So I made some progress. I went with 2D Sprite Shape. Currently I take the value from the axis, and multiply/add/whatever to make my snake bend left or right fairly smoothly. Few issues with speed and frame skips, but I'll work on that.

    Main issue now is the collider. Since I'm using a line, the polygon collider only goes in line with the points. So there's no collision until you get inside of the snake. How would I make the collider wider? I see offset, could I add two collider lines then and offset on each side of the sprite? But even then, the head wouldn't have good collision.

    Thanks!