PDA

View Full Version : shooting with angle


alekos
06-02-2005, 10:47 AM
good morning to all i am in serious trouble with a code i want a bullet to follow the angle of a cannon but no in straight direction but following the angle please help me

alekos
06-02-2005, 02:49 PM
this is what i have done but i want when i push the cannon a bomb will follow the direction of the cannon.for example if the cannon looks on the top the bomb will go on the top but with angle please help me someone with a fla :( :( :(

alekos
06-03-2005, 07:55 AM
this is my code for the shooting with angle but it isn't running can anyone help me please!!!!

_root.createEmptyMovieClip();
onMouseDown = function () {
g = 9.81;
v = 1;
cos_angle = Math.cos(_level0.kanoni.myDegrees);
sin_angle = Math.sin(_level0.kanoni.myDegrees);_
root.sfaira._visible = 1;
_root.sfaira._x = _root.kanoni._x;
_root.sfaira._y = _root.kanoni._y;
for (var i = 0; i<155; i += 0.1) {
balla_x = (v*v/g)*(sin_angle);
balla_y = (v*v/g)*(sin_angle)*(sin_angle);
_root.sfaira._x = _root.sfaira._x+balla_x;
_root.sfaira._y = _root.sfaira._y+balla_y;}};

henkep
06-03-2005, 09:35 AM
sin_angle = Math.sin(_level0.kanoni.myDegrees);_

Try to delete _ after ;

henkep
06-03-2005, 09:51 AM
A ball shall go from coordinats (1,1) to (100,100);
First you calculate the diffrences between the corr.
x1 =1;
y1= 1;
x2 =100;
y2 =100;

diff_x = x2-x1; // Res. 99
diff_y = y2-x2;

The you have to calculate the diffrence in time. For exampel if it shall take 10 sec. from (1,1) to (100,100).

henkep
06-03-2005, 09:56 AM
var timeWp2Wp:Number;
var time2Wp2:Number;
timeWp2Wp = this.time2seconds(TimeWP2)-this.time2seconds(TimeWP1);
time2Wp2 = this.time2seconds(TimeWP2)-this.time2seconds(this.getCurrentTime());
/*Multiple with 1000, to avoid rests*/
distance = (1-(time2Wp2/timeWp2Wp))*1000;
distance = Math.floor(distance);
distance = distance/1000;


here I calculate where the ball shall be. After 5 sec the ball shall be in the middle.
..time2seconds is my own function thats recalculate hour to seconds.

henkep
06-03-2005, 09:58 AM
this._x = int(diff_x)+int(diff_x*distance);
this._y = int(diff_y)+int(diff_y*distance);

alekos
06-04-2005, 08:50 AM
can anyone send a fla to help because i don't understand what to do here is what i have done please help me i would be very gratefull here is my code for the rotation can you send me any fla to help me

onClipEvent (enterFrame) {
if (!_root.motionFlag) {

myRadians = Math.atan2(_root._ymouse-this._y, _root._xmouse-this._x);
myDegrees = Math.round((myRadians*180/Math.PI));
_root.yChange = Math.round(_root._ymouse-this._y);
_root.xChange = Math.round(_root._xmouse-this._x);
this._rotation = myDegrees+145;
}
onMouseDown = function () {

g = 9.81;
v = 1;
cos_angle = Math.cos(_level0.kanoni.myDegrees +180);
sin_angle = Math.sin(_level0.kanoni.myDegrees +180);
_root.ball._visible = 1;
_root.ball._x = _root.kanoni._x;
_root.ball._y = _root.kanoni._y;

_root.motionFlag = true ;

};




sth ball


/* xi = v*cos_angle * i;
yi = v*sin_angle - 0.5*g*(i*i);
_root.ball._x = xi ;
_root.ball._y = yi;
trace("x:" + xi + " - y:" + yi )
*/

onClipEvent (enterFrame) {

g = 9.81;
v =- 0.01;
cos_angle = Math.cos(_level0.kanoni.myDegrees +180);
sin_angle = Math.sin(_level0.kanoni.myDegrees +180);

if (_root.motionFlag) {

i+=2
xi = v*cos_angle * i;
yi = v*sin_angle - 0.5*g*(i*i);
yi = yi/1000
xi = xi*10
_root.ball._x = _level0.kanoni._x + xi ;
_root.ball._y = _level0.kanoni._y + yi;
trace("x:" + xi + " - y:" + yi )

}

}

CyanBlue
06-05-2005, 04:33 AM
I have merged your posts... Please do not crosspost... :(