Forums

ForumsProgramming Forum

360 movement collisions

Posted Sep 4, '11 at 6:45am

ExplosionsHurt

ExplosionsHurt

262 posts

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.

 

Posted Sep 4, '11 at 2:00pm

Carlytoon

Carlytoon

329 posts

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 :D

 

Posted Sep 4, '11 at 2:06pm

Carlytoon

Carlytoon

329 posts

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.
 

Posted Sep 4, '11 at 2:08pm

Darkroot

Darkroot

2,879 posts

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.

 

Posted Sep 4, '11 at 6:08pm

arobegamr

arobegamr

130 posts

What version of Actionscript are you using?

 

Posted Sep 5, '11 at 1:38am

ExplosionsHurt

ExplosionsHurt

262 posts

Whoops.

I'm using AS3.

 
Reply to 360 movement collisions

You must be logged in to post a reply!