Pages: 1
Topic closed
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
What type of collisions are you trying to do? Just any old collision or accurate collisions?
Offline
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
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.
Offline
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
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
(( x-position of character <+> 10 )) )y
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)
Offline
Thanks MoreGamesNow! I'll try that right now.
Offline
Topic closed
Pages: 1