ForumsProgramming Forum360 movement collisions

5 1956
ExplosionsHurt
offline
ExplosionsHurt
251 posts
40

I've made a character-cannon thingy that can rotate and move around. I am now having troubles figuring out how to get the character to stop at walls.

I'm not looking for code. I'm just wanting to know what I have to do to make it stop at walls.

  • 5 Replies
Carlytoon
offline
Carlytoon
326 posts
235

Well, if you have rectangle walls, you can check if the character collides each side of the rectangle, for example if the character collides the top side of the rectangle you can set the vertical speed to 0 or you can use a while loop like this:
while(player collide rectangle top){
player.y++;
}

Remember that this only works for rectangles.
I hope this helps you

Carlytoon
offline
Carlytoon
326 posts
235

while(player collide rectangle top){
player.y--;
}

Ups, I forgot to tell how the code works...
If the player collides the rectangle top the loop gonna repeat until the player dont collide with the rectangle top, to stop the loop you need to decrement player.y until the player dont collide with the rectangle top.
Darkroot
offline
Darkroot
2,799 posts
1,120

A simple way is to use hiTestObject and have four different directional hit-zones. If the character moves into the "Left" hit-zone then it's does X to prevent the character to move through the left wall. It's not the best system but it's pretty easy to make.

arobegamr
offline
arobegamr
130 posts
540

What version of Actionscript are you using?

ExplosionsHurt
offline
ExplosionsHurt
251 posts
40

Whoops.

I'm using AS3.

Showing 1-5 of 5