This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-10-22 16:19:27

haloman298
New Scratcher
Registered: 2011-09-03
Posts: 18

I'm having trouble with making collision detectors

This is basically having a sprite bounce off of an object or wall.  I tried following the tutorial, but it messed up my game.

Offline

 

#2 2011-10-25 01:18:59

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: I'm having trouble with making collision detectors

What type of collisions are you trying to do?  Just any old collision or accurate collisions?


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#3 2011-10-26 23:06:23

haloman298
New Scratcher
Registered: 2011-09-03
Posts: 18

Re: I'm having trouble with making collision detectors

I guess a pretty basic collision.  I just want my sprite to be trapped in a room, not being able to pass by the walls.

Offline

 

#4 2011-10-27 00:16:45

schnrfl
Scratcher
Registered: 2011-10-11
Posts: 500+

Re: I'm having trouble with making collision detectors

Have you tried reversing its direction when it's touching a wall?
Also, knowing how to use absolute value and how degrees work helps too.


opposable thumbs • ubc • dvorak • help
sprach eˣius//Foresson

Offline

 

#5 2011-10-27 20:45:38

haloman298
New Scratcher
Registered: 2011-09-03
Posts: 18

Re: I'm having trouble with making collision detectors

Well, my game is a scrolling one, so should I just change the x scroll by 10 or something when a wall is touched?  Also, I can't get the collision detectors to stay a certain distance from my sprite.  They are all bunched up into the center of it, making them useless.

Offline

 

#6 2011-10-27 20:58:13

FallenIce
Scratcher
Registered: 2011-10-14
Posts: 100+

Re: I'm having trouble with making collision detectors

idk about this one sorry


http://i.imgur.com/Yc7aC.gif

Offline

 

#7 2011-10-28 10:12:36

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: I'm having trouble with making collision detectors

Well, the easy way out would be to download a collision detector script.  The more lengthy way out is to interpret this:


There are many ways to make collision scripts.  The collision scripts for a scroller are very similar to a basic platformer.  The differences is, instead of moving the character-sprite, you move all the platforms the opposite way.

If you know you're hitting a wall on the your right, move all the walls right.  Then you'll make no progress and it gives the appearance that you're moving left (or bouncing off the wall).

As to your problem with you collision detectors (I assume you have four sprites for the four directions), they should be on the outside (you probably already know that).  That their in the middle suggests to me that you're using the "Go To []" block.  To get them on the outside, either open up the Paint Editor and change their "centers" (click "set costume center").  For the "up" sensor, move the center down.  Then, when the "Go To []" block places the center of the costume on the center of your character, the sensor itself will be above.  For the down sensor move the costume center up, for the right sensor move the center left, and for the left sensor move the center right.  Make sense?

Alternatively use the "Go To x: () y: ()" block instead of the "go to []" block to manually move the sprites.  For the up block:

<go to x sad  ((  x-position of character  <+>  10  )) )y sad  y-position of character  ).


This makes the sprite go to a y-position above the character.  Change the x position for the left and right sensors.


Now, assuming you've read that and are thinking "That is too complicated, is there another way to detect collisions?".

I could go on and on about different methods, but I'll try to keep it concise.  I employed a relatively simple method in my first platformer series.  It doesn't look the best, but it worked, and that was all that was important to me as a developing Scratcher.  What I did was color the floor different than the walls.  Then, whenever I touched a wall, I would look at which direction I was going and move the opposite way.  An example is here.  To adapt this to a scroller, whenever the character-sprite touches a wall, I'd broadcast "bump right" or "bump left" and put the corresponding scripts in all the walls.  Alternatively, if you are using a "X" variable to keep track of your x-position, just change that and your walls should change automatically.

Last edited by MoreGamesNow (2011-10-28 10:13:15)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#8 2011-10-28 16:13:46

haloman298
New Scratcher
Registered: 2011-09-03
Posts: 18

Re: I'm having trouble with making collision detectors

Thanks MoreGamesNow!  I'll try that right now.

Offline

 

Board footer