Newgrounds.com — Everything, By Everyone.

Checking login status…

USERNAME:

PASSWORD:

Logging in…

Logged in as:
.
Logging out…
Inbox My Account Log Out


Forum Topic: Code for movieclip following cursor

(59 views • 4 replies)

This topic is 1 page long.

<< < > >>
None

ChuklesDaClown

Reply To Post Reply & Quote

Posted at: 5/13/08 05:58 PM

ChuklesDaClown NEUTRAL LEVEL 09

Sign-Up: 01/12/05

Posts: 142

I have gotten this code to work in AS2 what I am trying to acomplish is add a more elastic movement to the object does anyone know how to accomplish this?
current code:

onClipEvent(enterFrame) {
this._x = _root._xmouse+20;
this._y = _root._ymouse+20;
}

The road to madness is just the scenic route to insanity


None

gankro

Reply To Post Reply & Quote

Posted at: 5/13/08 06:49 PM

gankro EVIL LEVEL 11

Sign-Up: 09/16/06

Posts: 1,128

onClipEvent(enterFrame) {
_x = (_root._xmouse-_x)/25;
_y = (_root._ymouse-_x)/25;
 }

mayhaps? MAY have gotten the two swapped around... pretty sure its final - initial...

My Coding Portfolio (updated frequently)
If you stay in bed for long enough it will be socially acceptable to go to bed again

BBS Signature

None

ChuklesDaClown

Reply To Post Reply & Quote

Posted at: 5/13/08 08:51 PM

ChuklesDaClown NEUTRAL LEVEL 09

Sign-Up: 01/12/05

Posts: 142

well after some tweaking and asking around I came up with this only problem is its elasticity is way to high I need to get it to bounce a little less and for less time in other words not to stretch as much and for less time. anyone understand this enough to know which variables I need to change.

onClipEvent(load) {
this.momentumx = 0;
this.momentumy = 0;
}

onClipEvent(enterFrame) {
distx = this._x - _root._xmouse;
disty = this._y - _root._ymouse;
this.momentumx -= distx / 8;
this.momentumy -= disty / 8;

this._x += this.momentumx / 8;
this._y += this.momentumy / 8;
}

The road to madness is just the scenic route to insanity


None

gankro

Reply To Post Reply & Quote

Posted at: 5/13/08 09:28 PM

gankro EVIL LEVEL 11

Sign-Up: 09/16/06

Posts: 1,128

At 5/13/08 08:51 PM, ChuklesDaClown wrote: well after some tweaking and asking around I came up with this only problem is its elasticity is way to high I need to get it to bounce a little less and for less time in other words not to stretch as much and for less time. anyone understand this enough to know which variables I need to change.

onClipEvent(load) {
this.momentumx = 0;
this.momentumy = 0;
}

onClipEvent(enterFrame) {
distx = this._x - _root._xmouse;
disty = this._y - _root._ymouse;
this.momentumx -= distx / 8;
this.momentumy -= disty / 8;

this._x += this.momentumx / 8;
this._y += this.momentumy / 8;

mod the 8's to change elasticity. (must mod each pair equally or else will not work) the first pair will define how quickly it will snap the second pair will define how softly it will go in... I think... hard to picture this properly... to lazy to test...

My Coding Portfolio (updated frequently)
If you stay in bed for long enough it will be socially acceptable to go to bed again

BBS Signature

None

gankro

Reply To Post Reply & Quote

Posted at: 5/13/08 09:36 PM

gankro EVIL LEVEL 11

Sign-Up: 09/16/06

Posts: 1,128

alright, tested it, basically the 8's will not mod elasticity, just how slowly it will move, elasticity is a constant in this engine, basically, the object will stretch out to as far as it was in the opposite direction.

onClipEvent (load) {
	momentumx = 0;
	momentumy = 0;
}
onClipEvent (enterFrame) {
	distx = _x-_root._xmouse;
	disty = _y-_root._ymouse;
	momentumx -= distx/8;
	momentumy -= disty/8;
	_x += momentumx;
	_y += momentumy;
	momentumx /= 1.1;
	momentumy /= 1.1;
}

this will actually be elastic, mod "1.1" to mod elasticity.

My Coding Portfolio (updated frequently)
If you stay in bed for long enough it will be socially acceptable to go to bed again

BBS Signature

All times are Eastern Daylight Time (GMT -4) | Current Time: 12:14 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!