Search Unity

i need souce code to make algorith like that ?

Discussion in 'Scripting' started by m-y, Nov 22, 2014.

  1. m-y

    m-y

    Joined:
    Sep 22, 2013
    Posts:
    472
    hello
    i want the code that make the snake AI amazing like that
    it can find the food
    without i control it
    any advice to ?
    if there is no way to get the code of this algortihm
    so i want to know how to write algorithm doing something like that ?

     
    Stoven likes this.
  2. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    Stoven likes this.
  3. Stoven

    Stoven

    Joined:
    Jul 28, 2014
    Posts:
    171
    I never even heard about A* pathfinding until now, and it will work perfectly for the issue I came across recently. Thank you both.
     
  4. m-y

    m-y

    Joined:
    Sep 22, 2013
    Posts:
    472
    but i have another question about the snake move
    how to make the snake moving like that
    i mean
    there is a specific kind of moving snake moving with
    how to add this moving to the snake A* ?
     
  5. MattB79

    MattB79

    Joined:
    Sep 12, 2014
    Posts:
    20
    what do you mean make the snake move like that?
    Like the body and tail follow where the head went?
    or the path the head takes.
     
  6. Korno

    Korno

    Joined:
    Oct 26, 2014
    Posts:
    518
    The snakes body is just made up of a number of points, these points follow the points infront of it. Kinda like joints - joint 1 is the head, joint 2 follows joint 1, joint 3 follows joint 2 etc. If you do that, you will get the snakes body moving in the same way. How bendy you want the snake just depends on how many points you have.
     
  7. Stoven

    Stoven

    Joined:
    Jul 28, 2014
    Posts:
    171
    The concept of a Linked List, or Doubly Linked List structure might be helpful.

    Note, I am strongly emphasizing concept and not necessarily implying that you must use one. You can use an List as the backing array for the connected elements, and simply associate the next node as the i + 1 index from the array's current index, and associate the previous node as the i - 1 index from the array's current index.
     
    Korno likes this.