123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|733|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Basic Basement -> inaccurate angles :(

Thu, 24 Oct 2013, 00:29
spinal
I don't know if this is a monkey issue, or a math issue, but the following code is a bit inaccurate

It's meant to be a nice snake that follows the mouse, but the angles are all wrong, bits of the body float off in weird directions...


I'm sure I havent missed a step or anything. Any clues?

-=-=-
Check out my excellent homepage!
Thu, 24 Oct 2013, 02:26
Jayenkai
Had a play. Got some nice effects, and got the snake going crazy, but nothing that I thought was the effect you were after! Any further clues as to your expected style, lemmie know!

Quick Tip, though.. I've found that some Android devices absolutely HATE drawing ovals. Not sure why this is, but major slowdown if you do too many. (Hoppy Bobby became MUCH smoother when I switched the large circles to big sprites)


-=-=-
''Load, Next List!''
Thu, 24 Oct 2013, 03:28
shroom_monk
From what I can tell, you're trying to move each node of the snake to within snake-body-segment distance of the previous node, with the had attached to the mouse, right? Unfortunately, without Monkey, I can't run your code to see if that's what happening or not.

If that is what you're after, I think you can achieve the same effect without any trig, just using distance ratios, but I'm not sure if I've correctly deduced what you're going for here.

-=-=-
A mushroom a day keeps the doctor away...

Keep It Simple, Shroom!
Thu, 24 Oct 2013, 09:47
spinal
Thats exactly it!

like this -- https://processingjs.org/learning/custom/snake/

I've done this a couple of times in different languages, it looks like the angles aren't close enough to what they *should* be, so the tail will float off to one side or would straighten up if dragged in a straight line etc.

|edit|
Dammit!

pos_x and pos_y weren't floats.... fixed.


Have I learned anything from this? Probably not. Expect the same damn post in a couple of years about the next language I try to learn

-=-=-
Check out my excellent homepage!
Thu, 24 Oct 2013, 15:29
spinal

OK, now that the angles look right, time for a little collision detection to attempt to remove the possibility of the snake overlapping itself!


As you can see from the above code, I am attempting to check each segment agains the others, other than the one directly before or after.
Once a collision is detected, I check if a change in angle will result in less of an overlap, if so, do that.
It seems to work OK if the collision is in a clockwise direction, however, if it is in the other direction, it goes a little nuts. Anyone got any ideas on how to improve it?

-=-=-
Check out my excellent homepage!
Thu, 24 Oct 2013, 15:37
Jayenkai
First, you need only check "from this segment to the last", because anything before that has already been checked by a previous segment.
Less checks necessary, and results in less crazy movement.

.. Currently on iPad so no idea what else to tweak, just thought I'd jump in with that tidbit!

-=-=-
''Load, Next List!''
Thu, 24 Oct 2013, 16:02
shroom_monk
I'm not quite sure what your algorithm is meant to be here, but it has two mistakes in it regardless:
1) Your calculation of p1 is incorrect, because you forgot to square x2 and y2.
2) Even then, comparing p and p1 is meaningless, since p is the distance between two nodes on the snake, while p1 is the distance from your new node to the origin.

|edit| Also, is a collision algorithm even worth it? What if the head of the snake is dragged back through the body? Is there a sensible way of resolving that? |edit|

-=-=-
A mushroom a day keeps the doctor away...

Keep It Simple, Shroom!