Jump to content
  • Advertisement
Sign in to follow this  
Arjan B

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.

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

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


Link to post
Share on other sites
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.

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!