This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.
  • Index
  •  » Show and tell
  •  » custom collision detection (boring math- stay out- NO POSTING)

#1 2010-07-18 17:49:42

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

custom collision detection (boring math- stay out- NO POSTING)

We started talking about math stuff and I got all sidetracked into
this project.

project notes...

1) Draw any shape by clicking with the mouse. To finish, just click on the beginning of the line. Runs fine in Turbo.

-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!


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#2 2010-07-18 22:00:30

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: custom collision detection (boring math- stay out- NO POSTING)

Hey, I was just kidding about no posting...  hmm


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#3 2010-07-18 22:06:00

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: custom collision detection (boring math- stay out- NO POSTING)

Wow, that's incredible! Your projects never fail to impress me.

Now, how did you get it to recognize when the polygon was complete? It even seemed to "snap" the last bit together. That was so cool. And how it figured out when it was in the polygon was, wow...

Offline

 

#4 2010-07-18 23:09:43

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: custom collision detection (boring math- stay out- NO POSTING)

Thanks a ton again! It closes the polygon by checking the distance of each new end point against the first point made. If within a certain distance, it erases the last point because it was just close to 'closing', and re-writes the last point using the coords of the first point so that it closes perfectly.
And yeah, the whole deal was the collision detection part. I was gonna work on bouncing the bullet but I think instead I will 1)optimize (use variables instead of list data) 2) replace the bullet with another user-drawn polygon so that they will bounce off each other correctly according to what angles their faces meet at.

ps.. Although I always do as much of the scripting as I can manage on my own, I Googled a few pages up to get the algorithms correct. It still had my mind bent all night and part of today trying to get everything working together correctly.

I can't wait till I get to borrow another connection, I have several projects to upload including a finished moon game, a stop-motion movie my daughter and I made when I first got Scratch, a screen-saver with images of my artwork (I'm an artist and musician also) and maybe some other stuff. I have a cool step-sequencer called Cheesy Loops that is working and looking very cool. Gotta work on that when no one is around cause all the drum sounds drive everyone cept me nuts.

Last edited by Locomule (2010-07-18 23:18:52)


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 
  • Index
  •  » Show and tell
  •  » custom collision detection (boring math- stay out- NO POSTING)

Board footer