Slithering Snake

HXCTCreations - Custom level - from Android
PlayEdit6 players liked this.Log in to like this level.

Simple snake, rope, or whatever you call it. Each segments always keep a distance against another segments.


1 function seg_update(segments, range, cspd)
2 for i = 2, #segments do
3 local dx = segments[i].x - segments[i-1].x
4 local dy = segments[i].y - segments[i-1].y
5 local dist = math.sqrt(dx ^ 2 + dy ^ 2)
6 segments[i].x = segments[i].x - (dist - range) * cspd * dx
7 segments[i].y = segments[i].y - (dist - range) * cspd * dy
8 end
9 end

1: update function declaration
-segments is the table containing position of each segments.
-range is the distance of two segments in normal condition.
-cspd is the correction speed.
2: do the process on each but first segment.
3 and 4: calculate the segment's position relative to rlthe previous segment.
5: calculate the absolute distance to the previous segment.
6 and 7: move the segment to/away the previous segments, depending on the distance and correction speed.

Views: 467 Downloads: 169 Unique objects: 2 Total objects: 10

Discuss this level

Log in to comment on this level.
  • JupiterSky: Mine got so long it lost it's head. ^^
  • Linux: @HXCTCreations: make it swing between layers
  • Linux: @HXCTCreations: you should use 3d lines
  • Chad64: Wow, there's alot of math stuff that i have used in there but never really used it like that. Ill try to implement the code into into my level, ill give ya credit. Thx man :D
  • HXCTCreations: @Chad64: read the description.
  • JupiterSky: Hair in the bathtub simulator.
  • Chad64: Can you explain what's happening in that seg_update() function you made so that I could probably implement it on my wormy?
  • Chad64: damn, you do everything very fabulously
  • hosj12: Sweet would be better if camra followed
  • HXCTCreations: @Chad64:

LEVEL ID: 26853