Ansimuz Posted December 11, 2013 Share Posted December 11, 2013 Hi, What would be the logic or best way to create a entity followed by other entities to create a snake made of linked entities. For example a head entity that will be followed by other entities that form the body of the snake. BTW i am using impactJS Quote Link to comment Share on other sites More sharing options...
Antylum Posted December 11, 2013 Share Posted December 11, 2013 Hi!I think it depends on movement type - if it will be like on your picture, than it's approximately body.y = k*sin(body.x) Here is some information about movement types:http://science.howstuffworks.com/zoology/reptiles-amphibians/snake3.htmhttp://ealexeckman.webs.com/ Quote Link to comment Share on other sites More sharing options...
Ansimuz Posted December 11, 2013 Author Share Posted December 11, 2013 Thanks for i am thinking in something simple. Something like the animated gif in this post. I need the logic to make the body entities to follow the head entity and make a chain. Quote Link to comment Share on other sites More sharing options...
Rezoner Posted December 12, 2013 Share Posted December 12, 2013 So this is what I did here http://rezoner.net/labs/superrotoshooter There is an invisible dot that follows some path - and each let's say 25 ms this dot is spawning a pointthis.points.push[this.x, this.y];Also remember thisif (this.points.length > this.segments.length) this.points.unshift();Now the only thing that left is to pass these point positions to corresponding segments and make them move towards new destination. You can realize this using some kind of tween (easing) or implementing simple physics with velocity. I am pretty sure that there are more (clever) ways to do this tho. Quote Link to comment Share on other sites More sharing options...
pato_reilly Posted December 12, 2013 Share Posted December 12, 2013 Here is a solution I worked out in Phaser: http://www.patricko.byethost9.com/phaser-master/examples/_site/view_full.html?d=pato_reilly&f=pp_snake.js&t=snake Quote Link to comment Share on other sites More sharing options...
Ansimuz Posted December 12, 2013 Author Share Posted December 12, 2013 So this is what I did here http://rezoner.net/labs/superrotoshooter There is an invisible dot that follows some path - and each let's say 25 ms this dot is spawning a pointthis.points.push[this.x, this.y];Also remember thisif (this.points.length > this.segments.length) this.points.unshift();Now the only thing that left is to pass these point positions to corresponding segments and make them move towards new destination. You can realize this using some kind of tween (easing) or implementing simple physics with velocity. I am pretty sure that there are more (clever) ways to do this tho. Your game looks amazing! By the time a read your post i implemented a solution. This is what i did i spawned the body parts with a delay each part follow the same path so it looks like they are linked even thought they are just one after another following the same path. Like cars in a road. You implementation is a clever way. It may work to others. Thanks for everybody for your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.