|
|
|
#1 |
|
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;
}
Last edited by gouf08; 08-07-2007 at 06:39 PM. |
|
|
|
|
|
#2 |
|
Moderator
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:
|
|
|
|
|
|
#3 |
|
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. |
|
|
|
|
|
#4 |
|
Pumpkin Carving 2008
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. | |
|
|
|
![]() |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|