Sign in to follow this  

balls in round corners

This topic is 4749 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi can anyone help with a problem I'm having, I think its its fairly straightfoward, and I'm sure I'm doing it right but don't seem to be getting anywhere...well thats not stricty true, I've fudged it so it works, but I'm deeply unhappy with the code and would love to hear how others do it. I have a ball with x and y velocity (*256 for a degree of FP precision) travelling around a near frictionless table with round edges, not unlike an ice hockey rink I need the ball to swoosh around the round arc of the corners so long as the angle of entry is fairly close to parallel at the horizontal or vertical edge of the arc, and to simply deflect otherwise if the angle of entry is too steep. So the problem is 2 fold, whats the maths to do the swoosh? I can re-calc the new x and y positions ok, on the edge of the arc, but am having trouble altering the x and y speeds to allow a convincing swoosh effect. Also, how do I tell which angles should swoosh and which should rebound.. oh and as a complication its on a phone so no floating point maths, though I do have a fairly good fixed point lib, but I need it to be as simple as possible. hope you can help..I need sleep :)

Share this post


Link to post
Share on other sites
Well you shouldn't treat any differently to a normal collision.

If you calculate the normal to the surface at which the contact occurs, you should just reflect the velocity vector using that normal and correct the position so that it is just in contact with the surface. I can give you the code for that if you need, very simple...

Now when a ball comes around the rounded corner at a shallow angle, it should make a series of contacts with the surface which will produce that "swoosh" effect you are talking about.

The simplest is always the best solution, you shouldn't have any special code to handle this situation.

Share this post


Link to post
Share on other sites
would dearly love to compare code, my main issue seems to be a precision problem when calculating normals..trouble is its not consitant (or does not seem to be) so I've got huge catches in the corners checking for the ball exceeding the radius and pulling it back in...functional but duh!!!

Share this post


Link to post
Share on other sites
Well it worked for me... I made a 3d pool game consisting entirely of curved surfaces

Screenshots: http://users.skynet.be/sdsoftware/spacepool-screenshots.htm
Download: http://users.skynet.be/sdsoftware/files/SpacePoolDemo.exe

Anyway, It could well be a precision problem since you are not using floating point numbers.

I wouldn't really consider it a hack to move the ball so that it is just touching the edge of the table. But you need the reflection in there to make sure the velocity changes as well. Is that what you are doing already?

Share this post


Link to post
Share on other sites
hmmm no, not correctly, I'm just clamping it to the edge of the arc,recaluclating its velocity based on the new position, and trying to detect the angle and decide if it should "swoosh" or bounce...clearly I've got the wrong approach...
Given that I have the angle of the centre of the circle to the intersection, which seems to be accurate so long as its not too vertical (which is then fudged), the intersection point itself, the radius of the arc, and the xy speeds of the ball, whats the easiest way to work out the reflection?

Share this post


Link to post
Share on other sites
Well I don't have the exact code but i can recreate it for you:


// XYZ is a struct with 3 floats, x, y and z representing a vector
XYZ Normal; // this is a vector pointing in the direction normal to the contact surface of unit length
XYZ Velocity; // velocity vector of the ball

XYZ ReflectedVelocity = Velocity - 2*DotProduct(Velocity, Normal);


Thats pretty much it for the reflection. DotProduct is a function that finds the dot product of two vectors. And the XYZ struct is overloaded with the - operator to do a vector subtraction (i.e. just subtracting each of the components).

Share this post


Link to post
Share on other sites
it seems to me
that this series of small reflections adding up to a smooth 'swoosh'
would not work as well as the physics time interval gets large - instead of getting a smooth swoosh youd get a series of jagged bumps with velocity losses
maybe you should look into the time precision before looking at the fixed point position/velocity precision

also
what if you did an imperfect reflection
rather than reflect the velocity vector, fudge it so that the reflection is reduced in angle to be more parralel to the surface than it started
that might help keep it following smoothly


another thought
how do the mechanics of 'swoosh' work in a real hockey puck?
i suspect that having it roll against the curved wall, and thus loseing some of its translational energy might play a part in why it works...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
no the level of accuracy needed is not that high, its for a phone game and I needed a good balance of speed/accuracy so java could cope.

I fiddled around a bit with the precision and noticed a flaw in my argument passing/return system and it works just fine now...if I could find a really fast way to accuratly caclulate the point of intersection of the ball with the curve it'd be perfect, but as it stands, detecting its gone outside the arc, and forcing it back in with a known radius, while slightly off the point of intersection, works well enough for now.
Thanks for the help guys..

Share this post


Link to post
Share on other sites

This topic is 4749 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this