Collide with sprite

205 views
Skip to first unread message

imans314

unread,
Mar 31, 2015, 8:42:49 AM3/31/15
to mitappinv...@googlegroups.com
I am making a golf game (using the MiniGolf tutorial)

When I am using a sprite of my own the ball will not collide with the sprite on the sides of the sprite.
The top and bottom are fine.

Can anyone tell me how to fix this?
HitSprite.aia
HitSprite.PNG

Ghica

unread,
Mar 31, 2015, 8:57:12 AM3/31/15
to mitappinv...@googlegroups.com
So, what happens?

imans314

unread,
Mar 31, 2015, 9:13:54 AM3/31/15
to mitappinv...@googlegroups.com
it just slides throught, like it does not exists.

Ghica

unread,
Mar 31, 2015, 10:24:33 AM3/31/15
to mitappinv...@googlegroups.com
I think indeed something is wrong here. I will ask some people who know more than I do.
Cheers, Ghica.

Ghica

unread,
Mar 31, 2015, 10:25:47 AM3/31/15
to mitappinv...@googlegroups.com

Gareth Haylings

unread,
Mar 31, 2015, 11:49:40 AM3/31/15
to mitappinv...@googlegroups.com
Hi

I haven't looked at the project but might have an idea why the collide is not working. Speed is the number of pixels the sprite will move each interval. 

If you have 2 sprites on the screen one is 5x5pixels in size and the other is 15x15pixels in size. To ensure the collision detection is picked up make sure the speed not above 15 (i.e.this is 15pixels which is the big size of the 2 sprites) if you set the speed higher than this it mean sprite will jump right over the sprite without detection they have collided.

Using the following work around will ensure collision between 2 sprites is always detected
What you could do as a work around is set the interval to 1000 for a very slow movement and 1 from high speed. Keep speed as a constant of 1 (or smallest dimension of the largest sprite you want to detect collision with) when the sprite is to stop set the speed to 0.

Ghica

unread,
Mar 31, 2015, 3:13:22 PM3/31/15
to mitappinv...@googlegroups.com
No, the problem is that your calculation of the heading after a bounce is wrong. It is only OK for the top and bottom side of the smiley. For the sides, you have to calculate something else, after figuring out on which side the ball touched the sprite.
I think the calculation is rather complicated, I am not going to do it for you!
Cheers, Ghica.

Ghica

unread,
Mar 31, 2015, 6:24:06 PM3/31/15
to mitappinv...@googlegroups.com
I should add here that my remark about calculating the right heading was directed at imans134 not Gareth, who would certainly know much better than I do how to do this.
Cheers, GhIca.

Scott Ferguson

unread,
Mar 31, 2015, 10:52:36 PM3/31/15
to mitappinv...@googlegroups.com
Based on my AI classic project  > here < it seems that collisions of balls with sprites must deal with collisions on top and bottom differently from side collisions.
Here is my solution with AI2 blocks:

The modified project is attached.

---
sf
HitSpriteMod.aia

imans314

unread,
Apr 1, 2015, 3:55:44 AM4/1/15
to mitappinv...@googlegroups.com
Thanks for al the help, I will work with this.




Ghica

unread,
Apr 1, 2015, 4:07:29 AM4/1/15
to mitappinv...@googlegroups.com
Thank you Scott! 
I will keep this in my bag of tricks.
Cheers, Ghica.
Reply all
Reply to author
Forward
0 new messages