Sprites bounccing off Sprites

440 views
Skip to first unread message

Brandon Kidd

unread,
May 7, 2015, 6:01:05 PM5/7/15
to mitappinv...@googlegroups.com
Hey all,

I have searched this topic quite a bit on here but still not understanding what exactly is going on.  I have 30x30 sprite and I am trying to bounce it off another sprite.  Like others have mentioned the sprited bounces off other sprites off the horizontal sides just fine but it passes through the vertical.  I have tried adjusting my sprite dimensions and still no luck. My last attempt was 30x30 sprite and a 30x30 sprite target.  Can anyone help and explain what is going on behind the scenes with this issue?

thanks
Brandon

Scott Christy

unread,
May 7, 2015, 9:35:51 PM5/7/15
to mitappinv...@googlegroups.com
I have basically the same issue.  I have a ball sprite and 2 other sprites that serve as walls.



 I need the ball to bounce off the sprites like it does the edge of the canvas.  I can use this block coding to get it to correctly bounce off of the vertical wall but the problem is the ball passes through the horizontal wall.


Or I can get it to bounce of the horizontal wall if I change it to this but then the ball passes through the vertical wall.


I added in a text label to show me the heading of the ball when it is flung or when it collides with a sprite hoping that I could figure it out but I'm not having much luck.  I assumed that the heading of the ball went from 0 (heading directly to the right, 90 (heading directly up, 180 (heading directly left), 270 (heading directly down).  In other words 0 - 360.  I found however, that the ball fling heading was 0 to 180 when heading any direction upward, or 0 to -180 when heading in any direction downward.

I'm sure I'm missing something simple here.  How do I code my blocks so that I get the appropriate deflection regardless of the shape of the sprite the ball is bouncing off of?




Abraham Getzler

unread,
May 8, 2015, 8:46:22 AM5/8/15
to mitappinv...@googlegroups.com
Your bounce angle calculation needs work.
See my attachments.
ABG



diagonal_bounce_test.aia
dotted_line.jpg
ball_wrangling.jpg
bounce_heading_formula.jpg

Scott Christy

unread,
May 8, 2015, 9:50:11 AM5/8/15
to mitappinv...@googlegroups.com
Nope.  Still passes through the blocks. Attached is my AIA.

Another option I thought might work, although I'm sure it's not the best approach, is do an if statement that says if the height of the sprite the ball is colliding with is more than the width do the deflection calculation one way, else do it the other way.
Maze_game_help.aia

Brandon Kidd

unread,
May 8, 2015, 10:27:00 AM5/8/15
to mitappinv...@googlegroups.com
Abraham,

I have been testing your bounce heading formula and it seems that it still only works for when the ball bounces off a horizontal plane. It still goes through a vertical plane. I can tweak it so it is reversed and bounces off a vertical plane but then it will go through a horizontal plane.  It is difficult to get both cases to work. I tested the diagnol bounce test and it seems to work for the most part but there are still angles that the ball goes through the plane.  Maybe I am missing something.  I am going to work on this some more today and see what I can do.  Thanks for the help.

Brandon

Brandon Kidd

unread,
May 8, 2015, 10:50:05 AM5/8/15
to mitappinv...@googlegroups.com
Hey Scott,

I am going to be messing around with this today as well. Add me to hangouts or shoot me an email.  kiddr...@gmail.com

Brandon

Ghica

unread,
May 8, 2015, 10:54:27 AM5/8/15
to mitappinv...@googlegroups.com

This works fine for me, most of the time. I did not invent it myself, but anyway, maybe it helps you.
Cheers, Ghica.

Scott Christy

unread,
May 8, 2015, 11:36:36 AM5/8/15
to mitappinv...@googlegroups.com
Ghica - THANKS!!!  It works!

Brandon, try the block below.  You need to be careful about the width of your walls and the radius of the ball or else you get some weird behaviors but other than that it seems to work.


Brandon Kidd

unread,
May 8, 2015, 12:42:05 PM5/8/15
to mitappinv...@googlegroups.com
Great thanks guys!  I have been testing it and it seems to work about 95% of the time. Once in a while it sneaks through the wall still.  I am going to do a little more tweaking and see what I can do but it is a good solution.  I think Steve on here had a hand in this formula so thanks to him too.

Brandon

Brandon Kidd

unread,
May 9, 2015, 1:16:43 AM5/9/15
to mitappinv...@googlegroups.com
Hey guys, 

What do you think about this code?  I set all my vertical sprites/walls to a heading of 90 and all my horizontal sprites/walls to a heading of 0.  Seems to work pretty good for what I am doing.  

Brandon
Sprite_Bounce_Code_AI2.png
Reply all
Reply to author
Forward
0 new messages