Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411507 Posts in 69374 Topics- by 58429 Members - Latest Member: Alternalo

April 26, 2024, 12:38:10 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)How to make snake movement smooth not grid based like stihter io snake
Pages: [1]
Print
Author Topic: How to make snake movement smooth not grid based like stihter io snake  (Read 980 times)
umen
Level 0
**


View Profile
« on: October 03, 2016, 01:18:32 AM »

Hello all
i try to find the right formula to mimic the smooth none grid movement of the stihter io snake  .
i can do it manually to save each point the "head" movement  went and do some interpolation in between its body parts but it is very error prone.
also i find this : http://www.emanueleferonato.com/2014/06/10/html5-string-avoider-game-made-with-phaser/
which is not working in my case but do show something similar
here is a picture to express what i want to do :


any idea how to do it right ?
Thanks!
Logged
oahda
Level 10
*****



View Profile
« Reply #1 on: October 03, 2016, 01:35:02 AM »

Maybe use a sine wave and play with the settings.

Without considering rotation, assuming the snake is moving to the right as in your illustration, only the y would be affected by the sine wave. The x might be used as an input, but I don't know how good that would look when stopping and such. But maybe!

You'd have something like this (pseudocode):

Code:
foreach (segment in segments)
    segment.y = sin(segment.x);

Variations would include multiplying the sine function's input by some factor, and/or multiplying the result of the sine function by some factor. The former will affect the intensity of the waves and the latter how much each segment is offset on the y axis.

If you want to make this work for any angle, you'll have to bring in some linear algebra.
Logged

umen
Level 0
**


View Profile
« Reply #2 on: October 03, 2016, 02:07:34 AM »

Thanks , well I need it to any direction
Logged
oahda
Level 10
*****



View Profile
« Reply #3 on: October 03, 2016, 03:21:43 AM »

The other most recent thread is relevant to that:

https://forums.tigsource.com/index.php?topic=58121.0
Logged

umen
Level 0
**


View Profile
« Reply #4 on: October 03, 2016, 03:26:22 AM »

I asked , but it is not the same
Logged
oahda
Level 10
*****



View Profile
« Reply #5 on: October 03, 2016, 03:28:17 AM »

Oops, didn't realise that was your thread too.

I suggest you read these:

http://blog.wolfire.com/2009/07/linear-algebra-for-game-developers-part-1/

http://blog.wolfire.com/2009/07/linear-algebra-for-game-developers-part-2/

http://blog.wolfire.com/2010/07/Linear-algebra-for-game-developers-part-3/
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic