# Sucking a ball

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

## Recommended Posts

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

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

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

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

##### Share on other sites
Thanks for your replies! I'll go give it a try.

1. 1
Rutin
28
2. 2
3. 3
4. 4
5. 5

• 13
• 11
• 10
• 13
• 20
• ### Forum Statistics

• Total Topics
632948
• Total Posts
3009410
• ### Who's Online (See full list)

There are no registered users currently online

×