The method i use for left and right collisions is to create to create three integer variables, 'speed', 'canright', and 'canleft'.
On keydown> right:
- Code: Select all
x+=speed*canright;
canleft=1;
and on keydown> left
- Code: Select all
x-=speed*canleft;
canright=1;
and on collision > left side of platform
- Code: Select all
canright=0;
and on the right side
- Code: Select all
canleft=0;
Now the reason for 'speed' is so you can give the player a speed powerup at anytime without having to go back and change all these scripts. Usually I set 'speed' to 4 and canright and canleft both to 1 on player>createactor.
So when a player runs into a wall or platform, his xvelocity in that direction is reduced to 0; and all he has to do to reenable it...is push the other direction. I used this method in Gauntlet (on the demos page).
The script in this post has changed from the gauntlet script in that i've used '*' instead of 'if'. Its less code and less work for the cpu.
If you try it you'll notice that this gives a very solid left and right collision; and the player doesn't 'bounce' off the wall, nor does he 'stick' to it. Hope this helps.