Jump to content
  • Advertisement
Sign in to follow this  
toye

Wall Trouble

This topic is 4956 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In Flashmx 2004 i was using some code to move a cirlce around my screen. I also drew a line to make a wall. Now from the tutorial I was working off the code that made the cirlce move around worked perfectly but when it came to the cirlce not being able to move through the wall it still kept passing the ling. Here is the code I used on the ball onClipEvent (enterFrame) { if (Key.isDown(37)) { _x=_x-2; } if (Key.isDown(38)) { _y=_y-2; } if (Key.isDown(39)) { _x=_x+2; } if (Key.isDown(40)) { _y=_y+2; } if (hitTest(_level0.wall)==true) { _x=_x-2; } } any suggestions of how to fix this?

Share this post


Link to post
Share on other sites
Advertisement
Well - I don't use Flash, so take this with a pinch of salt - but if hitTest is working correctly, the only thing it would ever correct would be Key.isDown(39) - in all other cases, it just moves you -2 units on the x-axis if there's a hit. You'd probably be able to see this as a jump as it suddenly doubles in speed for one frame.

If your hitTest is working, then it needs to void the previous movement, so it needs to know which movement it last took - implement some flag. A better way (IMO) is make hitTest part of the movement process:

if(Key.isDown(37)){
hitTest(x, -2, _level0.wall);
}

hitTest now knows you want to move -2 units on the x-axis - so checks against _level0.wall. If this would mean hitting a wall, then hitTest doesn't implement the move, otherwise it does.

HTH,
Jim.

Share this post


Link to post
Share on other sites

onClipEvent (enterFrame) {
if (Key.isDown(37)) {
_x=_x-2;
if (hitTest(_level0.wall)==true)
{
_x=_x+2;
}
}
if (Key.isDown(38)) {
_y=_y-2;
}
if (Key.isDown(39)) {
_x=_x+2;
if (hitTest(_level0.wall)==true)
{
_x=_x-2;
}
}
if (Key.isDown(40)) {
_y=_y+2;
}
}


This will make the ball go back, if the ball hits the wall in his new position(only if u go left or right).

xIshtarx

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!