Ball to Line Elastic Engine with dynamic collision

Monkey Forums/Monkey Code/Ball to Line Elastic Engine with dynamic collision

Jesse(Posted 2012) [#1]
an elastic collision engine. very basic. similar to what I used for my Pool game:
http://www.mochimedia.com/games/play/8-ball-hustler


If there is enough interest, I will add ball to ball, ball to Arc, and ball to Circle collision.



[updated] 11-29-2012

* added multiple ball to wall collision. (no ball to ball collision)


[updated] 12-21-2012

*ball 2 ball collision implemented


Difference(Posted 2012) [#2]
Very nice.


ordigdug(Posted 2012) [#3]
Really nice. Please add additional collision elements. Please include more documentation/comments for a newbie like me to understand.


Jesse(Posted 2012) [#4]
Thanks guys.

I just updated source!

fixed a couple of bugs and added ball to circle wall collision.

also I am starting to document it.


benmc(Posted 2012) [#5]
It works pretty well.

I gave it a try, and added a square shape to the middle of the poly you had created, and the ball did a lot of strange things with lines at right angles, and when it hit the "tips" of the lines. The ball also managed to find its way inside the box at one point.

Here's my box if it saves some time for testing:

engine.AddWall(New LineWall(250,100,350,100))
engine.AddWall(New LineWall(350,100,350,200))
engine.AddWall(New LineWall(250,200,350,200))
engine.AddWall(New LineWall(250,100,250,200))


Jesse(Posted 2012) [#6]
Thanks for testing it Ben.

did you try it with the latest update?

I don't see any problems when I tried it right now and with gravity.

I did fix a bug that was causing it to lock and crash and it had to do with the end points.


benmc(Posted 2012) [#7]
@Jesse seems pretty good. I tried the same thing as the day before and watched it for a minute or two and didn't see the same thing happened, so maybe it's fixed up.

This is a great system, probably would have made my last 2 projects much easier :)


Sammy(Posted 2012) [#8]
Very impressive, I am sure it can be used by me in the future. Thank you Jesse!


Arthur(Posted 2012) [#9]
Great!
It is impossible to add multiple collidable balls right now?


Jesse(Posted 2012) [#10]
thanks Veggie and Arthur.

@Arthur

It can do multiple ball collision and response but fails with gravity. I have been trying to figure out the gravity factor but it still eludes me. the problem is that it uses a fixed gravity value integrated to x and/or to y but when the movement is smaller than the gravity factor, l it brings the ball speed back up to the speed of gravity. thats in relationship to a ball at rest with ground or another object.
it also since it uses recursion. it goes into an endless loop and crashes. it works fine with out gravity.

so until I figure it out, I am not going to implement it. unless someone wants to work with me on figuring it out than I'll share the code.

I have read some articles but are too technical. I barely completed a year of trig in college not much calculus skills here.


Jesse(Posted 2012) [#11]
Just added multiple ball to line collision. but no ball to ball collision yet.


Sammy(Posted 2012) [#12]
I was just re-looking over this post, did you manage to get the ball to ball collision working Jesse?


Jesse(Posted 2012) [#13]
The ball to ball collision works just can't get it to play nicely with gravity. I'll try to implement it as soon as I have some free time. I will have to refactor the logic integration in the engine. I'll have it done hopefully by tomorrow.


Sammy(Posted 2012) [#14]
OK thanks Jesse, I'm looking forward to your update.


Jesse(Posted 2012) [#15]
@Veggie

sorry about not posting this earlier but I just forced myself to work on this as I didn't really have any time. So I am tiredly falling asleep as I am typing this but got it done.

There might be some bugs as I didn't thoroughly test it before posting it. Any way, gravity and collision works good(I think). but If friction is added then there will be problems unless someone can figure it out, everyone is going to have to wait until I figure it out.

not too well documented but will add more documentation at a later time. I hope it's helpful to others.

I still need to add ball to arc collision but unless somebody really need it for their project, It will be a while before I add to it.


Sammy(Posted 2012) [#16]
I really appreciate the effort you put into this Jesse. Its such a handy piece of code.

The code ran fine and was very impressive. The only fly in the ointment was I got this error a when I left it running for a little while:

Monkey Runtime Error : InternalError: too much recursion

Any ideas?




Jesse(Posted 2012) [#17]
Oops!

its a bug that has to do with the collision with both the start point of one line and the end point of another when they are at the same location. when both points are in the same spot it's checking collision agains each other continually and causes the recursion bug.

for now just add a "False" parameter to the end of the "New LIneWall". That should take care of the recursion bug until I can figure out a real solution. Do that to lines that have the end point connected to the start point of another line. Sorry, I will look at it maybe monday.


Sammy(Posted 2012) [#18]
OK Jesse, again, thanks being so generous with your code. :)


Jesse(Posted 2012) [#19]
NP!