ForumsProgramming Forum360 movement collisions

5 4047
ExplosionsHurt
offline
ExplosionsHurt
249 posts
Nomad

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
324 posts
Nomad

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
324 posts
Nomad

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,763 posts
Peasant

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
Nomad

What version of Actionscript are you using?

ExplosionsHurt
offline
ExplosionsHurt
249 posts
Nomad

Whoops.

I'm using AS3.

Showing 1-5 of 5