-
Script path of bullet
I'm trying to script de movement of a bullet with a variable angle, variable wind speed.
this is what I have so far:
Code:
// gravity
var hoek1:Number = 90;
var grote1:Number = 8;
//Wind
var hoek2:Number = 45;
var grote2:Number = 5;
//krachten uitrekenen
var x1:Number = grote1*Math.cos(hoek1*Math.PI/180);
var y1:Number = grote1*Math.sin(hoek1*Math.PI/180);
var x2:Number = grote2*Math.cos(hoek2*Math.PI/180);
var y2:Number = grote2*Math.sin(hoek2*Math.PI/180);
//optellen krachten x
var x:Number = x1+x2;
//optellen krachten y
var y:Number = y1+y2;
I was thinking that you need to put the angle calculation into the formula. I think it should be a parabolic function. But how do I script it and how do I use my forces in it? I't used for a tanks game for pocket pc so the movie is not standard but 240*320
Thanx in advanced
-
Bacon-wrapped closures
Still working on a solution to a problem almost exactly like this. I think the solution lies in solving it in pieces. The combination of all the equations you need looks like this:
V*cos(t) = (a(xs-xf))/(-V*sin(t)+/-sqrt(V^2*sin(t)+2a(ys-yf)))
You really need to isolate t (the angle needed to get from (xs,ys) to (xf,yf) at a given velocity (V) and gravity (a). You could also solve for velocity if you've already determined t.
Good luck
Neal
-
Senior Member
You could use something like this:
code:
onClipEvent(load){
angle=-45;
angle=angle/180*Math.PI;
speed=40;
gravity=2;
wind=-15;
}
onClipEvent(enterFrame){
xspeed=speed*Math.cos(angle);
yspeed=speed*Math.sin(angle);
yspeed+=gravity;
this._x+=xspeed+wind;
this._y+=yspeed;
angle=Math.atan2(yspeed, xspeed);
speed=Math.sqrt(yspeed*yspeed+xspeed*xspeed);
}
Of course the values for speed/angle/gravity/wind should be changed to suit your game.
-
Bacon-wrapped closures
Oh, I guess I didn't read your post entirely. Yeah, tonypa has it right.
Neal
-
Originally posted by tonypa
code: angle=angle/180*Math.PI;
what is Math.PI?
Last edited by allme4myjesus; 05-24-2005 at 06:58 AM.
-
Senior Member
Originally posted by allme4myjesus
what is Math.PI?
Pi -
http://en.wikipedia.org/wiki/Pi
It is used in my post to convert between radians and degrees.
Math.PI is constant built into Flash.
-
oh, duh, well thanks I needed that
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|