ScratchData LogoScratchData
Back to Locomule's profile

custom collision detection

LOLocomule•Created July 18, 2010
custom collision detection
36
18
1003 views
View on Scratch

Instructions

Draw any shape by clicking with the mouse. Don't draw around the bullet or its red/black status will be reversed but either way, it will still work. To finish, just click on the beginning of the line. Runs fine in Turbo.

Description

-This project uses lots of fun math (lol) to do collision detection on a polygonal object. It does this by comparing A. a line going from wherever the bullet is to where it will be next compared against.. B. One at a time, every line segment of the polygon -It checks to see if the two lines intersect and if it does, at what X,Y coordinate on the screen. -Then it checks to see how far the bullet is from that intersection point. If it is close enough it activates a trigger that either switches to it's "inside" or red costume or back to it's "outside" or black costume. -Technically, this is "faking" a check to see if it is inside the polygon because the state is set by colliding with a side. It does that fine now, but as usual, speeding up the bullet means you must check for collisions farther and farther away from the actual point of contact. Otherwise you get that deal where the sprite goes into the object before the detection kicks in, etc. -The great solution to not faking the "inside" status is to have the script track whether the bullet is right or left of the line as it will always be one or the other. Except of course when it is actually on the edge but by giving that up, you get detection all the way through the polygon so it is unnoticed and worth the trade. -Despite the hours spent, this is still the first version of this project. I will make the user drawn polygon move or rotate. I will make the bullet bounce off the polygon according to whatever side it hit. Um, I think I had other plans too but right now my brain hurts?!?! Yet another project inspired by our discussions in the All About Scratch forum. Peace everyone!

Project Details

Project ID1199512
CreatedJuly 18, 2010
Last ModifiedJanuary 9, 2019
SharedJanuary 9, 2019
Visibilityvisible
CommentsAllowed