Home Tutorials Forums Articles Blogs Movies Library Employment Press

 ActionScript.org Forums Simple Multi Directional Shooting
 Register FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

 01-15-2011, 07:43 AM #1 stilianos Registered User   Join Date: Nov 2010 Posts: 16 Simple Multi Directional Shooting I'm having a little trouble coding in multi-directional shooting in my game: Basically I have: Code: ```if (left) { player.x -= player.agility; boltDir = 270; } if (down) { player.y += player.agility; boltDir = 180; } if (right) { player.x += player.agility; boltDir = 90; } if (up) { player.y -= player.agility; boltDir = 0; } if (up && right) { boltDir = 45; } if (up && left) { boltDir = 315; } if (down && right) { boltDir = 135; } if (down && left) { boltDir = 225; }``` boltDir is the direction of the fired object, the above code works great, the only problem is 50% of the time if you are trying to do a diagonal shot for example up-left, it will get stuck and go left or up not diagonally. Anyone know how to improve this? Thanks
 01-16-2011, 04:48 PM #2 rrh throw a trace() in there   Join Date: Dec 2006 Posts: 1,982 How are the down, left, up, right values set?
 01-18-2011, 05:44 AM #3 stilianos Registered User   Join Date: Nov 2010 Posts: 16 event listener of keyDown and keyUp for the arrow keys.
 01-18-2011, 01:15 PM #4 rrh throw a trace() in there   Join Date: Dec 2006 Posts: 1,982 Okay, that sounds like it *should* work. Throw some traces in there to see if the values of them are right, and if the "if" statements are executing when you'd expect them to. Code: ```trace('values=',up,right); if (up && right) { trace('up + right'); boltDir = 45; }``` If these are all working as you'd expect, look next at what it does with boltDir. If the values aren't right, double-check the keyDown and keyUp listeners.

 Thread Tools Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home ActionScript Forums Group     ActionScript 3.0     ActionScript 2.0     ActionScript 1.0 (and below)     Simple Stuff (Newbies) Flash General Questions     Flash 10 General Questions     Flash 9 General Questions     Flash 8 General Questions     Other Flash General Questions Flex     Flex 2, 3 & 4     Flex 1 Extensions and Plugins     Components     JSFL - Extending Flash Desktop, Mobile and non-browser Environments     AIR (Apollo)     FlashLite / Portable Devices Development     Projectors and CDs Supporting Technologies     HTML and JavaScript     haXe     Server-Side Scripting     Flash Remoting     Flash Media Server General     Best Practices     Gaming and Game Development     Animation and Effects     Flashants Support Forum Community Boards     General Chat     Just for Kicks Challenges     Detention Flash In Action     Site Check     Cool Sites     Widgets Decommissioned     Projects and Positions CMS Forums     Announcements Board     Content Postings / Updates     Product Review Requests     CMS Technical Questions     Process Questions     Collaboration & Suggested Articles

All times are GMT. The time now is 07:06 AM.

///