I have been looking (and failing) for a script that allows an object to guide to another object. I am trying to create a guided missile, but I cant figure out how to make an mc guide to another mc at a constant speed and not if (this._y>=target._y){ this._y-=2 } because that will create an unnatural effect. greatful for any help thanks =D
You can put the first part in an on load event if you only want it to shoot towards it when fired. Else, you can just put it all in an on enter frame event. Note that obj is the object it is tracking and YOUR_SPEED is the speed of the object that is tracking.
Excellent code, Dank! If this flash actionscript is too much, then please refer to this site for a dialog on what you're attempting to do. It is a discussion on moving a movieclip and manipulation and helps explain some of what Dank is referring about.
Here are other sites that might help: 1) OOS - this guy is a genius!!! 2) Ed mack 3)TonyPa - who's very protective but has one of the best sites.
Dank, when I try this code out, the object moves away from the target object heres what I am doin onClipEvent (load) { YOUR_SPEED=2 xDis = _root.obj._x-_x; yDis = _root.obj._y-_y; radAngle = Math.atan2(yDis, xDis); _rotation = int((radAngle*180/(Math.PI))); } onClipEvent (enterFrame) { if (_rotation>180) { _x -= (YOUR_SPEED*Math.sin(Math.PI/180*_rotation)); _y += (YOUR_SPEED*Math.cos(Math.PI/180*_rotation)); } else { _x += (YOUR_SPEED*Math.sin(Math.PI/180*_rotation)); _y -= (YOUR_SPEED*Math.cos(Math.PI/180*_rotation)); } } and if I put the beginning peice inside the Enterframe, it moves in a circular motion around the object lawl, what iam doing wrong?
ok, idk what i am doing wrong here, so i uploaded a lil sample of what i am doing lol. fp.dunadan.net/guidance.swf if you click it reorients the rocket to a new position, but its not exactly moving towards the target if you know what i mean. heres the source code if you want to look into it more indepth fp.dunadan.net/guidance.fla