To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > General Help > Games

Reply
 
Thread Tools Search this Thread Display Modes
Old 08-07-2007, 06:32 PM   #1
gouf08
Junior Member
 
Join Date: Aug 2007
Posts: 2
[Help]/[Problem] Help with Archery Sim

Hi, I have been looking around all over the web to find useful hints and code that can help me accomplish what I am trying to do.

I want to create a archery game. Yes I know, its been done too many times, right? But I got interested in doing one as my first game. Now I just started reading up on ActionScript 2.0 and I am using Flash 8 Pro for this game. I am at the point where I want to simulate the flight of an arrow, like it would fly in the real world. So right now, I want to shoot a arrow (at a constant speed and angle, for now) and I want it to fly across the screen as it would in real life.

The archery game environment is from left to right, meaning you start off from the left and enemies com from the right. And you shoot to the right (but can also shoot to the left, up down, and any other direction) you can also move around freely to a certain point.

I really suck at this trig stuff you have to use to simulate the flight of a arrow but right now, this is what I have for code. NOTE: this code is placed onto the first frame on a layer called "actions" the actual arrow (which is a movie clip) is on another layer called "arrow" with a instance name of arrow1 and movie clip name of arrow. Also the registration point on the arrow MC is in the middle, and I drew the arrow facing to the right so like this: ---->

Code:
var angle = 45;
var rAngle = angle - 90;

arrow1.onEnterFrame = function(){
	var speed = 5;
	
	this._x += speed * Math.sin( angle * Math.PI / 180 );
	this._y += speed * Math.cos( angle * Math.PI / 180 );
	
	this._rotation = rAngle;
	angle -= 1;
	rAngle += 1;
};

function rotation(dx:Number, dy:Number):Number {
   return Math.atan2(dy, dx) * 180/Math.PI;
}
So any help that anyone can give me will be greatly appreaciated. I have tried other forums but they never respond or have no information on what I am trying to do exactly.

Last edited by gouf08; 08-07-2007 at 06:39 PM.
gouf08 is offline   Reply With Quote
Old 08-08-2007, 06:16 AM   #2
tonypa
Moderator
 
tonypa's Avatar
 
Join Date: Jul 2001
Location: Estonia
Posts: 8,138
You have cos and sin mixed up and I am not sure why you need so several angle variables.

PHP Code:
var angle = -45;
arrow1.onEnterFrame = function () {
    var
speed = 5;
    
angle += 1;
    
this._x += speed * Math.cos (angle * Math.PI / 180);
    
this._y += speed * Math.sin (angle * Math.PI / 180);
    
this._rotation = angle;
};
__________________
My games, Tile based tutorials, Vectors, Latest finished game Ononmin
tonypa is offline   Reply With Quote
Old 08-08-2007, 04:39 PM   #3
gouf08
Junior Member
 
Join Date: Aug 2007
Posts: 2
Woah? Your code works way smoother than my own. For that example I was trying to do the same thing you just did but look at the code quality difference. Thanks.

Now I have to figure out how to use this to simulate the flight of an arrow? Anyone got suggestions? Any will be greatly appreciated.
gouf08 is offline   Reply With Quote
Old 08-08-2007, 04:55 PM   #4
ImprisonedPride
Pumpkin Carving 2008
 
ImprisonedPride's Avatar
 
Join Date: Apr 2006
Location: Grand Rapids MI
Posts: 2,165
Set a base speed for the x and y directions. Then, adjust them based on the angle of the direction you're firing.

angle = directionYouWantToFireIn;


Oh and if you make a global variable called deg2rad, make it equal to Math.PI / 180; and replace it in your current code, you'll eek out a little bit smoother gameplay.
__________________

| Windows 7 Professional | Ubuntu 9.10 | San Diego A8N32-SLI Deluxe | AMD64 4000+ OC 2.97GHz | 3GB DDR 3200 | 512MB nVidia 7600 GT | 512MB nVidia 7800 GTX | Quad-Monitors |
| CS4 Actionscript 2.0 | CS4 Actionscript 3.0 | Java | Javascript | C++ | Visual Basic/.net | HTML | XML | PHP | MySQL | AutoHotKey |
| Working on a project? I'm available for freelance. |
ImprisonedPride is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > General Help > Games

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 -4. The time now is 06:03 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.