How to make ball pass through a ring but only at a certain angle

josh.wong0402@gmail.comjosh.wong0402@gmail.com Member Posts: 1
edited April 2016 in Help Wanted

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

  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2016

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

  • wongj19wongj19 Member Posts: 45
    edited April 2016

    @Socks said:
    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)

  • SocksSocks London, UK.Member Posts: 12,822

  • SocksSocks London, UK.Member Posts: 12,822

    Sorry, I couldn't resist.

    :)

  • fZoleefZolee Member, PRO Posts: 34

    @Socks, lol :D

  • SocksSocks London, UK.Member Posts: 12,822

    @josh.wong0402@gmail.com said:
    How do i make a ball go through a ring but only at a certain angle. . .

    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.

  • wongj19wongj19 Member Posts: 45

    how do I attach a picture?

  • SocksSocks London, UK.Member Posts: 12,822

    @wongj19 said:
    how do I attach a picture?

    Upload it to a free image hosting site and post the link here.

  • wongj19wongj19 Member Posts: 45

    something similar to this
    thanks

  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2016

    @wongj19 said:

    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.

  • wongj19wongj19 Member Posts: 45

    @Socks said: but what would happen if the ball came from underneath or from the side (see image below)

    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?

    @Socks said: In that case you could simply have two small circle actors at each (horizontal) end of the hoop that the ball collides with.

    Sorry to bother you again, but could you please tell me exactly where to place to 2 circular actors?

  • wongj19wongj19 Member Posts: 45
    edited April 2016

    @Socks pls reply

  • SocksSocks London, UK.Member Posts: 12,822

    @wongj19 said:
    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?

    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)

    @wongj19 said:
    Sorry to bother you again, but could you please tell me exactly where to place to 2 circular actors?

    At the left and right edges of the hoop.

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    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.

  • wongj19wongj19 Member Posts: 45

    @Lost_Oasis_Games said: 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.

    Would I need to make an invisible actor at the bottom of the ring to do this?

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    @wongj19 said:

    @Lost_Oasis_Games said: 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.

    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.

  • wongj19wongj19 Member Posts: 45

    Thanks :)

Sign In or Register to comment.