How to make ball pass through a ring but only at a certain angle
josh.wong0402@gmail.com
Member Posts: 1
How do i make a ball go through a ring but only at a certain angle, if it tries entering at any other angle, it collides with the ring.
Any help would be good.
thanks
Comments
At the point of contact measure the angle between the ring and the ball using the vectorToAngle function, this will allow you to determine whether the ball should be allowed to pass.
By the way if you specify only a certain angle (let's say 45°) then you will probably never get the ball to pass through the ring as the the odds of the ball being at this angle to the ring will be astronomical, perhaps one in billions (I'm not sure how many decimal places angles are measured to), you might need to round the vectorToAngle results to the nearest 1 or 2 or even 5 degrees, which would be the equivalent of checking for a range of angles between - for example - 40° and 43°.
I'm sure your explanation was very good but I don't really understand. Could you please take a screenshot of what you are talking about. (btw this is josh.wong0402@gmail.com)
Sorry, I couldn't resist.
@Socks, lol
Can you be any more specific, as often happens on the forums, someone could spend time working out some code for you assuming that this ring is side-on, like in a plaformer, only to find out they were wasting their time as it's actually isometric or viewed from above or moving from left to righ or growing and shrinking in size (or a thousand other things that would mean their efforts were wasted).
Perhaps a quick sketch of what it is you are trying to acheive would be useful.
how do I attach a picture?
Upload it to a free image hosting site and post the link here.
something similar to this
thanks
Ok, thanks, that makes more sense now.
The easiest way for any of this would be to set up a few invisible actors, that the ball is set to collide with . . . but what would happen if the ball came from underneath or from the side (see image below), or from anywhere outside of the two red lines ? Would it simply bounce off ?
If you just want a realistic basketball hoop then I think the angle the ball entered the hoop at wouldn't really matter ? In that case you could simply have two small circle actors at each (horizontal) end of the hoop that the ball collides with.
If possible, the ball would be able to move through the hoop but no points would be added to the score unless the ball is on the way down. Is this possible?
Sorry to bother you again, but could you please tell me exactly where to place to 2 circular actors?
@Socks pls reply
You can have a rule that checks that the ball collides with the hoop (or perhaps an actor lower down than the hoop) and also checks that the ball's Y-linear-velocity is less than 0 (which means it's moving downwards)
At the left and right edges of the hoop.
Yes this type of mechanic is very tricky. Especially if you want to simulate an air ball where the ball passes by the hoop. You're going to need to evaluate a bunch of conditions based on position and directional velocity et... My game canAball faced lots of these issues and was tricky to get right. To simplify things you may need to just make the ball collide with the net and drop straight down and not bounce like hitting the rim. I would make the rim and net two seperate actors to help differentiate between the two.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
Would I need to make an invisible actor at the bottom of the ring to do this?
I would use custom collisions. you can trace a custom collision area for both the ring and net. Using this method you could trace the two sides of the net and leave the top and bottom open. Same with the ring, trace a small area left and right and leave the middle open. Check out my video on it.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
Thanks