Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Basketball Basket

Author
Message
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 13th Nov 2014 19:44
Hi.

I create a simple basketball game.now i need know how can check that The ball enters the basket?
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 13th Nov 2014 20:03
lets see some code.... its easier for people to help if we can see what your working with.

Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 13th Nov 2014 20:14
here is my code:

SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 13th Nov 2014 20:29
when i get home after work i will take a look at it if no body else has.

SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 14th Nov 2014 01:06 Edited at: 14th Nov 2014 01:09
ok had a look at it....

you've got 2 options

you can create a hoop with collision on it and detect for collision between the ball and the hoop the same way you have with your ball to the ground.

or you can calculate the ruff area where the hoop is and check the x,y position of the ball to see if its within the same area as the hoop.

maybe x+10 to x-10,y+10 to y-10 ish in that area maybe you get a point.

i see your still using the percentage system.... i really do not recomend this for a new coder at all... I consider myself a good coder and i dont use the percentage system. Its not because i cant wrap my head around it... its because i choose a method thats much easier to work with. AppGameKit will add padding on those devices that do not fit your virtual resolution.... so why not let it do the work and just code to a specific resolution. AppGameKit will scale it to fit for you.

Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 14th Nov 2014 08:59
Thanks SoftMotion3D.

If I good understand your mean this 2 way are not good idea.

for method 1:

you say:
Quote: "you can create a hoop with collision on it and detect for collision between the ball and the hoop"


but if the ball collide with hoop and no enters the basket can't say the ball is enter the basket.



for method 2:

you say:
Quote: "or you can calculate the ruff area where the hoop is and check the x,y position of the ball to see if its within the same area as the hoop"


If I define a point then check if the X and Y Position of the ball is same with X and Y defined point now can say the ball is enter the basket.but if the ball cross the under basket and put to define point we can't say the ball enter the basket.

haliop_New
User Banned
Posted: 14th Nov 2014 09:15
what i think you should do is this :

the basket should be 3 sprites.
1st , the left side with physics (static)
2nd , the third side with physics (static)
3rd is the actual basket mask or the sprite you showed above without any physics at all.

then when you shoot the ball it will collide with the 1st and the 2nd then it might get in the basket and might not depend of how you throw it.

so you get something like this :



so the ball will actually fall between the two physics sprites or edges of the basket if you want.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 14th Nov 2014 09:33
yes if I create static side for my basket can do it. but my basket is Woven Cotton and good not seem that have static physics.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 14th Nov 2014 10:09
I think if change hoop maybe can do method 2 that calculate a point of basket. but there is a Problem with this hoop that when I use polygon shape in SetSpriteShape( Basket, 3 ) for add physics cover around my hoop and the ball can't enter it. how can fix it?

with SetPhysicsDebugON() can see green border around hoop.

Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 14th Nov 2014 10:22 Edited at: 14th Nov 2014 10:23
This is what I would do...

Red = Static Physics Sprites
Green = Transparent Sprite (with no physics)

Then just do a collision check with Ball + Green sprite...

Attachments

Login to view attachments
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 14th Nov 2014 10:23
I'd probably create a small hidden sprite located inside the basket. Test for collision against that and check direction of ball at the same time to prevent and false hits where the ball travels up from underneath.

Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 14th Nov 2014 11:52 Edited at: 14th Nov 2014 11:53
@ Funnell7

if the ball from under basket collide to green sprite What should I do?
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 14th Nov 2014 11:54
Quote: "if the ball from under basket collide to green What should I do?"


There are many things you could do... See if you can figure something out first... Hint CJB has already provided a potential solution...
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 14th Nov 2014 11:58 Edited at: 14th Nov 2014 12:02
I can't do CJB solution.
in other engines there are functions for check sides of sprite then can check (e.g) if the ball collide to under green sprite return false. and if collide to top of green sprite return true. but i can't see this Ability in AGK.
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 14th Nov 2014 12:14 Edited at: 14th Nov 2014 12:14
Quote: "in other engines there are functions for check sides of sprite then can check (e.g) if the ball collide to under green sprite return false. and if collide to top of green sprite return true. but i can't see this Ability in AGK."


No, but you could easily do this with 2 sprites... Then check the order in which the ball collided, if top then bottom, then you know its good...



Is it possible for the ball to go completely through the basket from underneath? If not, then this method should work...

Attachments

Login to view attachments
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 14th Nov 2014 12:34 Edited at: 14th Nov 2014 12:35
Quote: "
No, but you could easily do this with 2 sprites... Then check the order in which the ball collided, if top then bottom, then you know its good... "


I test it and announced the result.

but also there is another problem. We assume the ball enter the basket,now the ball should cross between left and right basket (Red line). how can do it?

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 14th Nov 2014 12:41
I do think you should sit down with a cup of coffee, some paper and a pencil and draw diagrams until you find a solution.

-- Jim - When is there going to be a release?
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 14th Nov 2014 12:51 Edited at: 14th Nov 2014 12:54
Quote: "I do think you should sit down with a cup of coffee, some paper and a pencil and draw diagrams until you find a solution."


Lol...

Behdadsoft, I'm assuming the net is just an image and not something fancy which actually moves like a net would? If so, do not apply any physics to the basket image. The only thing that should be physics enabled in the above diagram (the one I posted) are the red sprites. The green sprites and the actual basket sprite should have no physics so the the ball can pass through them...

EDIT: Re-read your post, I see what you mean now, you want the ball to fall through the net and not out the sides... Makes sense... Need to think about that one...
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 14th Nov 2014 13:00 Edited at: 14th Nov 2014 13:01
Ok, this is getting a bit messy now lol... Maybe someone has a better solution, but you could do something like this...



Leave the blue sprites as non-physics initially. Once you have checked that the ball entered the basket correctly, enable static physics for the blue sprites...

Once the ball has fallen through past the blue sprites, delete the physics... You'll need to mess around with the green sprites to get it correct, but you get the idea...

Attachments

Login to view attachments
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 14th Nov 2014 13:11 Edited at: 14th Nov 2014 13:13
it's not bad idea but i don't want create Tens sprite for this basket.I see other basketball games that have Oval ring below this picture that make the ball fall Direct to ground.



but there is a Problem when I add polygon physics shape to it, cover around it and the ball can't cross from hoop.how can fix this problem?
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 14th Nov 2014 14:07
i think funnell7's solution is perfect....dont worry about creating several sprites. AppGameKit can handle it just fine.

Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 14th Nov 2014 14:22 Edited at: 14th Nov 2014 14:23
OK, thanks all for help. but if there is any Problem I say in this topic.
xGEKKOx
AGK Master
15
Years of Service
User Offline
Joined: 7th Dec 2008
Location: Italy
Posted: 14th Nov 2014 14:29
3D or 2D is very simple...
Is not based on the collision, but on the player capacity.
The CPU will decide if it will go in or out

Login to post a reply

Server time is: 2024-11-25 11:25:56
Your offset time is: 2024-11-25 11:25:56