Sucking a ball

Started by
3 comments, last by Arjan B 15 years, 3 months ago
Now that title seems.. weird. But here's what I mean: Picture: The blue thing is a Sucker, the orange part is it's sucking area and the other thing is a ball ;) Info: There are going to be multiple Suckers in my game and one Ball. The Suckers are stationary but they can rotate. When they suck, the ball is drawn towards them (the closer to the Sucker, the stronger the sucking). I think I could figure this part out on my own by looking up Earth's gravitation in my old schoolbook. But these Suckers don't suck all around them, only in a certain direction. Question: Could anyone help me at how to make these Suckers suck or give me a push in the right direction? Thank you in advance, Arjan (PS: They need to be able to blow too, but I think that won't be hard to figure out once they can suck. )
Advertisement
Only apply the force when the ball is within the aspiration cone. Look online for point-in-cone (or point-in-triangle) tests to determine that. You might want to make the aspiration power change with the distance to the cone axis, too.
I presume this is a 2D environment, which should simplify matters somewhat. Now if you want a discrete cut-off when the ball is outside of the triangle, then a simple point-in-triangle test will do the job, as ToohrVyk mentions. If however you want the power to fade with deviation from a certain angle (as well as radially), there are simple methods for that too. For the discrete (on/off) behaviour, you'll just want to use something like the inverse square law for calculating the force acting on the ball (directed towards the "sucker" of course), setting the force to zero whenever the ball is outside of the triangle.
An alternative to triangle intersection testing:

If you know the direction that the sucker is facing as an angle and you add a little bit you get one limit of the aspiration triangle (max), if you subtract a little bit then you get the other limit of the triangle (min). If you use the dot-product to find the angle between the sucker's look-at vector (calculatable from the angle it is facing - and vice versa for that matter) and the displacement vector, from the sucker's position to the ball's position, then that gives the angle of the ball relative to the sucker (target).

To determine when to suck is now (almost) trivial:

if (target >= min && target <= max) suck(ball);

I say almost trivial because I've neglected to handle that fact that negative angles represent the same orientation as large positive angles, that's still easy to detect though.
Thanks for your replies! I'll go give it a try.

This topic is closed to new replies.

Advertisement