Home Tutorials Forums Articles Blogs Movies Library Employment Press
Prev Previous Post   Next Post Next
Old 10-23-2011, 10:23 AM   #1
Registered User
Join Date: May 2011
Posts: 9
Default [AS3] Hit detection

Hey guys. Well I got bored and decided to make a small game.
But I have ran into an issue with making walls, ages ago I downloaded a source code for a game with hit detection for walls, and I thought it was decent enough to use here. Its just a Boolean for everytime someone comes in counter with a wall. There are no errors, it is just not very effective. Any tips on making this work more realistic, currently I can go into the wall but it does push me out, and if I go in threw the top of the wall it just pushes me threw (I know what causes it, as I am just adding onto the X and Y coordinate, but I can't think of anything to fix that. Thanks!

ActionScript Code:
stage.addEventListener(KeyboardEvent.KEY_DOWN, right); stage.addEventListener(KeyboardEvent.KEY_DOWN, left); stage.addEventListener(KeyboardEvent.KEY_DOWN, up); stage.addEventListener(KeyboardEvent.KEY_DOWN, down); var hitWall:Boolean = false; var player:Shape = new Shape(); player.graphics.beginFill(0x0000FF); player.graphics.drawCircle(5, 5, 5); player.y = 350; addChild(player); var theWall:wall = new wall(); addChild(theWall); var checkDec:Timer = new Timer(1); checkDec.addEventListener(TimerEvent.TIMER, checkHitDec); checkDec.start(); function checkHitDec(event:TimerEvent) : void {        if(Shape(player).hitTestObject(theWall)) {         hitWall=true;         player.x += 1         player.y += 2         hitWall=false        } } function up(bmove:KeyboardEvent):void{     if (bmove.keyCode==Keyboard.UP && hitWall==false){         player.y-= 10     } }; function down(bmove:KeyboardEvent):void{     if (bmove.keyCode==Keyboard.DOWN && hitWall==false){         player.y+= 10     } }; function right(bmove:KeyboardEvent):void{     if (bmove.keyCode==Keyboard.RIGHT && hitWall==false){         player.x+= 10     } }; function left(bmove:KeyboardEvent):void{     if (bmove.keyCode==Keyboard.LEFT && hitWall==false) {         player.x-= 10     } };
TheNooblet is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 03:58 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.