Hi, fellow scratchers I'm working on a game, but I'm having trouble with collision scripts. I want to make it so the character will NOT be able to move in a certain direction when touching a collision object. I must add that the "map" that the character will be traveling on will be a top view, not a side view. What I keep ending up with is the character becoming completely immobile when touching the collision object. Anyone know a good script for collision? Thank you
(p.s. I do not want my character to change direction or "bounce", that becomes VERY annoying...)
Offline
I don't know of any good way to do it without bouncing.
What I do is have two personal (for this sprite only) variables, called "last xpos" and "last ypos".
Then, in my moving script, I have this:
when gf clicked forever set [last xpos v] to (x position) set [last ypos v] to (y position) moving script if <touching color [#000000]?> //use the color you don't want to go through go to x: (last xpos) y: (last ypos) end end
Offline
Thank you so much scimonster! This really helped! The tiny bit of bouncing is fine
Offline
I do something similar, but with the x-change and y-change separate, so if you, say, jump into a ceiling, your horizontal movement isn't affected.
when gf clicked forever set[old_x] to (x position) set[old_y] to (y position) x-movement-script if<touching [wall/ceiling]?> set x to (old_x) end y-movement-script if<touching [wall/ceiling]?> set y to (old_y) end end
Last edited by MoreGamesNow (2012-03-04 15:35:43)
Offline
See the project mentioned in this thread.
Offline
you could have a special collision sprite for the main character, so if one point of the collision box is touching the collision object the character will stop moving.
Offline