# Physics issue in a pinball game

I’m struggling to get the physics right with a gravity effect I’m trying to create.

I’ve created a plane with a 5 degree slope, with flippers, collidable objects and I’m trying to make an object near the bottom of my table that will collect the ball if it enters a radius, stop in (in a fashion that sucks the ball towards the hole) and then once it reaches the hole, spits it back up the table.

What I’m struggling with is a nice way of ensuring that the ball will suck towards the hole as I want. With this being a pinball game, the ball can be going very quickly and my suck effect can’t enact enough of a force on it. If I set the suck strength value too high, it quite often will suck but then the force applied will be too strong and then the ball will leave the radius of the object.

The best way I’ve found is to do this in my fixed update. I’m not sure I really should be editing a rigidbody’s velocity directly and this feels wrong:

``````Vector3 offset = transform.position - collider.transform.position;
offset.y = 0;

collider.rigidbody.velocity += pullForce * timeInCollider * offset;

timeInCollider += Time.fixedDeltaTime;

timeInCollider = Mathf.Clamp01(timeInCollider);
``````

I’ve determined that I need to divide the process into three steps:

1. Dampen the movement speed of the ball when it enters the radius of the sucking object
2. Suck the object (which also slows the ball down as it gets nearer the center)
3. Once settled then spit the object.

If someone could break down if those steps are correct and if so how I am best to approach each of those steps that would be great.

Thanks

if you know the radius of the “suck field”, you can pass the velocity of the ball in as a variable to determine the force required to “grab” it. the force direction could be calculated as the vector between the center of the field, and the point in which the ball hit the trigger field. then in each fixedupdate, recalculate the “grab” force between the center of the ball and center of your gravity field.

if you wanted the ball to get grabbed in a way that simulates a movement like water flushing down the toilet, you could apply an increased force over the amount of time you wanted to ball to reach the center… which might cause and acceleration affect.

also over time, you could apply an angular damping to slow it down.

another idea would be to make the “suck field” plane angled downward. after the contact perpendicular force is applied, you may only need to adjust the angular dampening with the ball in the field over time. this combined with the sloped “suck field” would probably be all that is needed to get it to the fields center.

once the object has reached its’ “sleep” velocity, you could have it signal the “suck field” to switch to a “spit field” and kick it out…

maybe that would help.

I think you are missing an important step…

2.5 when object is within a specified “close enough” radius, just move the ball to the hole and set velocity to 0.

It is very hard to hit an exact target when applying forces. Between time sampling error and round off error, you really need
to treat the target as a circle around the actual target with a very small radius.