I've made a custom movement in which when you press the up, down, left, or right arrow keys, the player moves 40 pixels in that direction; but I cant get the player to detect a collision and stop when it hits an obstacle. Does anyone have any ideas???
ya, fourty pixels is a huge gap, you are not moving it 40 pixels, you are teleporting it 40 pixels. Which means that anything that is within those 40 pixels doesn't get detected.
What Destroyer said was pretty much spot-on...though you might want to change it so that each direction starts off using a different fastloop, like so:
upon pressing left
• start loop 1 for 40 loops
upon pressing right
• start loop 2 for 40 loops
upon pressing up
• start loop 3 for 40 loops
upon pressing down
• start loop 4 for 40 loops
loop trigger 1 AND player is not overlapping a backdrop
• set x of player to x of player - 1
loop trigger 2 AND player is not overlapping a backdrop
• set x of player to x of player + 1
loop trigger 3 AND player is not overlapping a backdrop
• set y of player to y of player -1
loop trigger 4 AND player is not overlapping a backdrop
• set y of player to y of player +1
The reason why I say this is because it would allow for the player to move in diagonals when two directions are pressed.
or you could use detectors.
your tecnique with "bouncing back" with the X/Y pos, andyUK is good though it'll look quite bad when you'll go in and out of the wall repetetively.
why go 40 pixs at one time? in SquareRunner i used counters to count how many pixels it should go. I mean like:
Upon pressing (UP) + counter (Y pos) is 0 + ActiveObj(detector UP) is not overlaping backdrop
-Set counter (Y pos) to -8
Counter (Y pos) is less than 0
-Set pos of (player) to pos of (player)-4
-sub 1 to (Y pos)
and the same for the other directions.
That way it moves 32 pixels in every direction smoothly without overlaping walls.