Hello, I have an issue I’m trying to work out. I have a bird that is randomly flying around, but right now the bird only faces one way, wether it is going forward or backwards. I would like to get it to face the opposite direction, if it is flying in the opposite direction. (I hope this is clear). Below is the code that I have for the clip. I am new to flash 8, and I’ve gotten this code from one of the great tutorials here. Any help is greatly appreciated.
onClipEvent (load) {
//data you may want to change
width = 640;
height = 480;
speed = Math.round(Math.random()*2)+1;
//initial positions
x = this._x=Math.random()*width;
y = this._y=Math.random()*height;
x_new = Math.random()*width;
y_new = Math.random()*height;
}
onClipEvent (enterFrame) {
//x movement
if (x_new>this._x) {
sign_x = 1;
} else {
sign_x = -1;
_rotation = Math.atan2(this.yspeed, this.xspeed)*180/Math.PI;
}
dx = Math.abs(x_new-this._x);
if ((dx>speed) || (dx<-speed)) {
this._x += sign_x*speed;
} else {
x_new = Math.random()*width;
}
//y movement
if (y_new>this._y) {
sign_y = 1;
} else {
sign_y = -1;
}
dy = Math.abs(y_new-this._y);
if ((dy>speed) || (dy<-speed)) {
this._y += sign_y*speed;
} else {
y_new = Math.random()*height;
}
}
In case it matters, here is picture of the bird, perhaps it will help better explain what I want.