I am working on figuring the movement of snake vs blocks game from about 20 days, i succeded to make a smooth follow of tail but the problem is the gap in between the tail pieces when i try to move the snake fast from one place to another.
Need Help!
@Nishchhal If you don’t mind copying the script that makes the snake move maybe I can help.
btw is is C# or Java because if java i don’t know
Sor
Sorry for the late reply here is the script.
-
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
-
- public class Snake : MonoBehaviour
- {
- public Transform head;
- public Transform[ ] segments;
- List breadcrumbs;
-
- public float segmentSpacing; //set controls the spacing between the segments,which is always constant.
-
- void Start()
- {
- //populate the first set of crumbs by the initial positions of the segments.
- breadcrumbs = new List();
- breadcrumbs.Add(head.position); //add head first, because that’s where the segments will be going.
- for (int i = 0; i < segments.Length; i++) // we have an extra-crumb to mark where the last segment was…
- breadcrumbs.Add(segments*.position);*
-
- }*
-
-
- void Update()*
-
-
- {*
-
-
- if (headDisplacement >= segmentSpacing)*
-
-
- {*
-
- breadcrumbs.Insert(0, head.position); // add a new one where head is.*
-
- headDisplacement = headDisplacement%segmentSpacing;*
-
- }*
-
-
- if (headDisplacement != 0)*
-
-
- {*
-
- segments[0].position = pos;*
-
- segments[0].rotation = Quaternion.Slerp(Quaternion.LookRotation(breadcrumbs[0] - breadcrumbs[1]), Quaternion.LookRotation(head.position - breadcrumbs[0]), headDisplacement / segmentSpacing);*
-
- for (int i = 1; i < segments.Length; i++)*
-
- {*
- pos = Vector3.Lerp(breadcrumbs[i + 1], breadcrumbs*, headDisplacement / segmentSpacing);
- segments.position = pos;
- segments.rotation = Quaternion.Slerp(Quaternion.LookRotation(breadcrumbs - breadcrumbs[i + 1]), Quaternion.LookRotation(breadcrumbs[i - 1] - breadcrumbs), headDisplacement / segmentSpacing);
_- }
- }
- - }
- }
[/i][/i][/i][/i][/i][/i]
The thread that i took refrence from is
https://discussions.unity.com/t/439335 *_
- {*
Eagerly looking for help on this topic. Any help will be very helpful.
Thanks in Advance.