Hello,
Let me share my experience with trying to make a snake with Box2D.
To make a clear - I have spend 3Weeks+ on this problem only and I have no clue about solution.
This is fully repeatable and easy to reproduce.
I have bulled a snake which goes out of the whole in ground.
Snake is build with 20+ balls connected with WeldJoints.
Snake have a square head (to have a larger mass and allow user to easy operate with Snake)
Snake tail is connected to the ground with PrismaticJoint so it can't ever fully goes-out of the whole.
It looks more-less like this.
||||||||||||||||||||||||||||||
X------O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-[]
||||||||||||||||||||||||||||||
X Ground
------ PrismaticJoint
O- Ball with WeldJoints (I have tried other types of joints and problem was same) - joints are short and connect centers of balls. instead of balls you can use squares - result is same.
[] head.
I have set parameters in a way to that snake can not make a loop with his body. joints tries to keep it one straight line - user is trying to bend it. result is quite realistic.
Other thing is, that sometime it happen that we have a loop in snake body and I have no clue how to fully avoid it. (I explain it to myself ,that it's because of calculation frequency = velocityIterations = 16;positionIterations = 6;)
When user start to play with snake, 2 wrong things happens.
1. snake is trying to keep his body in one line, user us trying to bend the body.... but sometime user bend snake too much (still no loop) and snake is bended from this moment. (no more straight - it looks like joints have some limit, and when we bend more than that - they remember new state as orginal one and never back to straight line.
2. When user plays with snake more, and point 1 happens few times. snakes often spontaneously start shaking his body, with very high frequency and large distance. shake becomes than like bubbles in boiling watter - this is no longer snake - it is just like electrons in atom.
I detect this states checking distance between 3 balls if distance between ball 1 and 3 is much smaller then between 1 and 2 or 2 and 3 than it shakes.
No way to stop, no way to prevent.
A.... user moves the snake with mouse joint mouse_frequency=0.9; mouse_dumping=0.9;
PS: I have impression that it have something to do with calculation frequency. I have seen that having 5 snakes it happens more often than having only 1.
Is it possible that mouse joint which is asynchronous here may cause such issue? (touching of the snake may happen few times between physics single update)
I am programming now only on iPad with Xcode and I don;t have compilable test bed for this environment to give you example how it works.
Mariusz
Let me share my experience with trying to make a snake with Box2D.
To make a clear - I have spend 3Weeks+ on this problem only and I have no clue about solution.
This is fully repeatable and easy to reproduce.
I have bulled a snake which goes out of the whole in ground.
Snake is build with 20+ balls connected with WeldJoints.
Snake have a square head (to have a larger mass and allow user to easy operate with Snake)
Snake tail is connected to the ground with PrismaticJoint so it can't ever fully goes-out of the whole.
It looks more-less like this.
||||||||||||||||||||||||||||||
X------O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-[]
||||||||||||||||||||||||||||||
X Ground
------ PrismaticJoint
O- Ball with WeldJoints (I have tried other types of joints and problem was same) - joints are short and connect centers of balls. instead of balls you can use squares - result is same.
[] head.
I have set parameters in a way to that snake can not make a loop with his body. joints tries to keep it one straight line - user is trying to bend it. result is quite realistic.
Other thing is, that sometime it happen that we have a loop in snake body and I have no clue how to fully avoid it. (I explain it to myself ,that it's because of calculation frequency = velocityIterations = 16;positionIterations = 6;)
When user start to play with snake, 2 wrong things happens.
1. snake is trying to keep his body in one line, user us trying to bend the body.... but sometime user bend snake too much (still no loop) and snake is bended from this moment. (no more straight - it looks like joints have some limit, and when we bend more than that - they remember new state as orginal one and never back to straight line.
2. When user plays with snake more, and point 1 happens few times. snakes often spontaneously start shaking his body, with very high frequency and large distance. shake becomes than like bubbles in boiling watter - this is no longer snake - it is just like electrons in atom.
I detect this states checking distance between 3 balls if distance between ball 1 and 3 is much smaller then between 1 and 2 or 2 and 3 than it shakes.
No way to stop, no way to prevent.
A.... user moves the snake with mouse joint mouse_frequency=0.9; mouse_dumping=0.9;
PS: I have impression that it have something to do with calculation frequency. I have seen that having 5 snakes it happens more often than having only 1.
Is it possible that mouse joint which is asynchronous here may cause such issue? (touching of the snake may happen few times between physics single update)
I am programming now only on iPad with Xcode and I don;t have compilable test bed for this environment to give you example how it works.
Mariusz