-
how would i constrain dragging an object along a 45 degree angle
ive seen tutorials on how to duplicate mc's and position the dragged object that way, but i thought this would be easier seeing that the object follows a constant path
thanks
-
I think something like this would do:
on the movie clip you want to drag, place this action
onClipEvent (load) {
x1 = _x;
}
onClipEvent (enterFrame) {
x2 = _x;
this._y += (x1-x2);
}
^1letser
-
hmmm, i placed a mc on the stage and placed this code on the mc
onClipEvent (load) {
x1 = _x;
}
onClipEvent (mouseDown) {
if (hitTest( _root._xmouse, _root._ymouse, false)) {
startDrag ("");
}
}
onClipEvent (enterFrame) {
x2 = _x;
this._y += (x1-x2);
}
when i clicked on the mouse it shot straight up and vanished, although playing with it a little longer a managed to keep it on screen when i moved the mouse a lot slower
thanks for you help so far
-
Senior Member
First, it will depend on where your 45 is, in which quadrant. But let's assume that you are on the first on, y>0, x>0, so your 45 graph is y = x. With that in mind, you can build something like
Code:
onClipEvent (load) {
x0 = this._x;
y0 = this._y;
angle = 1; // to switch the direction change to -1
function YinX(x) {
//will return the Y position about the X that enters.
return (angle * (x - x0) + y0);
}
}
onClipEvent (enterFrame) {
if (drag) {
this._x = _root._xmouse;
this._y = YinX(this._x);
}
}
onClipEvent (mouseDown) {
if (this.hitTest(_root._xmouse, _root._ymouse))
drag = true;
}
onClipEvent (mouseUp) {
drag = false;
}
This works just fine.
Regards,
Leo Lima
-
I see the problem but I haven't got much time to solve it. you can use the code by Leo Lima, it will work just fine.
sorry about the code,
^1letser
-
Senior Member
You just forgot to consider y0. That's a simple algebra problem, about finding the equation of a straight line.
Regards,
Leo Lima
-
nice one Leo Lima!!!
that works a treat, much faster than the one ive developed myself.
i ended up duplicating a load of mcs to create the 45 degree line and then positioning the draggable object to them....tedious and messy
thanks
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
|