balls in round corners

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

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 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 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 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

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 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 on other sites
SpaceDude
I mailed you but you may not get it, any chance I can see your code? maybe I can spot the problem by comparing?

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 vectorXYZ Normal;        // this is a vector pointing in the direction normal to the contact surface of unit lengthXYZ Velocity;      // velocity vector of the ballXYZ 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 on other sites
yeah, I'm doing that, though only a 2D vector...I'm getting the feeling more and more I need to try to up the precision of the fixed point to fix this...thanks for the help

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 on other sites
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..

1. 1
2. 2
3. 3
Rutin
17
4. 4
5. 5

• 14
• 9
• 10
• 12
• 17
• Forum Statistics

• Total Topics
632906
• Total Posts
3009156
• Who's Online (See full list)

There are no registered users currently online

×