PDA

View Full Version : Random Rotation



TheCanadian
July 17th, 2005, 06:12 AM
Does anybody know how I could go about creating random motion for a movie clip. I want it to be a smooth motion to one point, and when reaches that point it randomly rotates to another, etc. Sort of like the random motion tutorial, but, you know, without the moving and with the rotation. ;) Any help is greatly appreciated.

TheMaxExp
July 17th, 2005, 07:04 AM
Oh, you mean like something spinning.

signifer123
July 17th, 2005, 07:05 AM
sure thats fairly simple heres a sample code it see where the point is reletive to the box then goes towards it until it is there then it rotates and you can set another point for it. Althoguh i just got lazy since this would only work everytime when the speed is set to 1 so its perfect if you raise the frame rate from 12 just put this on the mc you want ot move and rotate


i attached a test file i m ade for this

onClipEvent (load) {
_root.targetx = Math.ceil(Math.random()*550);
_root.targety = Math.ceil(Math.random()*400);
speed = 1;
}
onClipEvent (load) {
_root.targetx = Math.ceil(Math.random()*550);
_root.targety = Math.ceil(Math.random()*400);
speed = 1;
}
onClipEvent (enterFrame) {
function MoveTo(pointx, pointy) {
if (this._y>pointy) {
this._y -= speed;




} else if (this._y

<pointy) {
this._y += speed;
}
if (this._x>pointx) {
this._x -= speed;




} else if (this._x

<pointx) {
this._x += speed;
}
}
if (this._y != _root.targety || this._x != _root.targetx) {
MoveTo(_root.targetx, _root.targety);
} else {
this._rotation = Math.ceil(Math.random()*360);
_root.targetx = Math.ceil(Math.random()*550);
_root.targety = Math.ceil(Math.random()*400);
}
}


My Code keeps Getting Erased!!! code attached in AS and Fla Files

Blackspirit
July 17th, 2005, 09:07 AM
I think thats becuase your using the [code] tag instead of the [code] tag :D

signifer123
July 17th, 2005, 09:32 AM
Ohh thanks i think the post is fixed now

TheCanadian
July 17th, 2005, 09:02 PM
Thanks for the help but it seems that I have written my question wrong. Instead of random motion, I want random rotation. So the movieclip rotates randomly its regestration point without the movieclip moving along the x and y axes. Thanks again.