Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
jefinho

Fixed speed - independent of distance

Recommended Posts

Hi there,

 

I'm trying to rotate a number of objects through TweenLite into different directions. Some objects have to bridge a greater distance than others, so they must move faster within a fixed time. Thereafter, the same objects - which have bridged a longer distance before - can bridge a shorter distance which makes them move slower.

I would like the speed of rotation always the same, regardless of the distance they must bridge. Is this possible?

 

I've looked to this option:

http://www.kirupa.com/forum/showthread.php?t=332600

 

But I guess it's a little too limited for me, because my animation is continuous. So the objects rotate all the time (using onComplete:pickAnotherRotation). Sometimes a big rotation, sometimes a small rotation.

 

Can anyone give me some idea's?

Thanks!

Link to comment
Share on other sites

Maybe I'm misunderstanding the question, but couldn't you just use a separate tween for the rotation? If you're using TweenLite, just make sure you either set overwrite:false or (even easier), use OverwriteManager to set the default overwrite mode to AUTO. OverwriteManager.init(2).

 

If you need to do a tween at a constant velocity, you can do that pretty easily with the physicsProps or physics2D plugins which are membership benefits of Club GreenSock (http://www.greensock.com/club/) but I'm not sure you really need those in this situation.

Link to comment
Share on other sites

Thanks for your reply.

I'm not sure if that will help.

It's pretty hard to explain what I am trying to accomplish. Maybe some code will clear things up.

 

I have 8 movieClips (_family) containing 4 elements (m). Those 4 elements have to rotate at the same speed, independent of the distance they have to take.

The elements rotate to a random position, and when the position is reached the "countMovements" function will be called. This function checks if all the elements are at their final distention.

When that happens, the process starts all over again, with new positions to rotate to. This is done by recalling the randomMemberRotation function.

 

private function randomMemberRotation():void
	{
		for (var i:uint = 1; i<=8; i++)
		{
			var f:MovieClip = this["_family" + i];
			// randomDir gives a number between 0 and 360
			var randomRot1 = randomDir();
			var randomRot2 = randomDir();
			var randomRot3 = randomDir();
			var randomRot4 = randomDir();
			// rotSpeed is a number, lets say 5
			// countMovements checks if the 32 elements are at their final distination
			twM1 = new TweenMax(f.m1,rotSpeed,{rotation:randomRot1,repeat:0,ease:Linear.easeNone,onComplete:countMovements});
			twM2 = new TweenMax(f.m2,rotSpeed,{rotation:randomRot2,repeat:0,ease:Linear.easeNone,onComplete:countMovements});
			twM3 = new TweenMax(f.m3,rotSpeed,{rotation:randomRot3,repeat:0,ease:Linear.easeNone,onComplete:countMovements});
			twM4 = new TweenMax(f.m4,rotSpeed,{rotation:randomRot4,repeat:0,ease:Linear.easeNone,onComplete:countMovements});
		}
	}
}

}

 

 

So, how can I realize a "fixed" speed for the elements - no matter how far the distance is?

Thank so much trying to help!

Link to comment
Share on other sites

Sounds like just a math issue then, like:

 

var rotSpeed:Number = 25; //degrees per second
var randomRotation:Number = (Math.random() * 360) - 180; //Flash always describes rotation between -180 and 180 degrees
var rotationChange:Number = randomRotation - mc.rotation;
var tweenDuration:Number = Math.abs(rotationChange / rotSpeed);

TweenLite.to(mc, tweenDuration, {rotation:randomRotation, ease:Linear.easeNone});

Link to comment
Share on other sites

Thank you for your reply.

For as far I can see this won't work within this concept - but I'm not a mathematician.

 

In my idea there are 32 elements rotating at the same time to a random location. This will not happen once, but - in theory - infinite. So when all the 32 elements are finished with a rotation, they will rotate to a new position, etc, etc.

In all cases, the rotation speed has to be the same, no matter how many times the final rotation destination has changed.

 

Maybe I just don't understand the way tweenLite, or your math-solution works.

Anyhow, thanks for your help.

Link to comment
Share on other sites

Yep, the whole idea is to figure out the correct duration for your tween based on how much the rotation is changing. That gives all the rotation tweens the appearance of rotating at exactly the same speed. That's the formula I wrote out for you (it was just for one object, but I intended for you to take the concept and integrate it into your code wherever you needed it).

 

Your edited code could look like this:

 

private function randomMemberRotation():void {
        for (var i:uint = 1; i            var f:MovieClip = this["_family" + i];
           twM1 = buildRotationTween(f.m1);
           twM2 = buildRotationTween(f.m2);
           twM3 = buildRotationTween(f.m3);
           twM4 = buildRotationTween(f.m4);
        }
}

function buildRotationTween(mc:DisplayObject):TweenMax {
   var rotSpeed:Number = 25; //degrees per second
   var randomRotation:Number = (Math.random() * 360) - 180; //Flash always describes rotation between -180 and 180 degrees
   var rotationChange:Number = randomRotation - mc.rotation;
   var duration:Number = Math.abs(rotationChange / rotSpeed);
   return new TweenMax(mc, duration, {rotation:randomRotation, ease:Linear.easeNone, onComplete:countMovements});
}

Link to comment
Share on other sites

Thanks a lot for your help en patience.

For as far I can see now, your solution is working.

 

The application is a little more complicated than just objects randomly rotating. That's why I had trouble implementing your code.

Once again: THANKS!

Link to comment
Share on other sites

Just one more question.

Is it possible that the ShortRotation plugin will mess things up? In the following code I will rotate an object to a specific position using the ShortRotation plugin:

 

private function buildRotationTween(mc:DisplayObject, rot:Number):TweenMax
	{
		var rotSpeed:Number = 5;//degrees per second
		var specRotation:Number = rot;
		var rotationChange:Number = specRotation - mc.rotation;
		var duration:Number = Math.abs(rotationChange / rotSpeed);
		return new TweenMax(mc,duration,{shortRotation:{rotation:specRotation},ease:Linear.easeNone,onComplete:countMovements});
	}

 

I'm using this, because I want my object to rotate the shortest distance possible to the given position.

Link to comment
Share on other sites

Yep, if you use shortRotation, you'll need to adjust your code.

 

private function randomMemberRotation():void {
        for (var i:uint = 1; i            var f:MovieClip = this["_family" + i];
           twM1 = buildRotationTween(f.m1);
           twM2 = buildRotationTween(f.m2);
           twM3 = buildRotationTween(f.m3);
           twM4 = buildRotationTween(f.m4);
        }
}

function buildRotationTween(mc:DisplayObject):TweenMax {
   var rotSpeed:Number = 25; //degrees per second
   var randomRotation:Number = (Math.random() * 360) - 180; //Flash always describes rotation between -180 and 180 degrees
   var rotationChange:Number = randomRotation - mc.rotation;
   if (Math.abs(rotationChange) > 180) {
       rotationChange += (rotationChange     }
   var duration:Number = Math.abs(rotationChange / rotSpeed);
   return new TweenMax(mc, duration, {shortRotation:{rotation:randomRotation}, ease:Linear.easeNone, onComplete:countMovements});
}

Link to comment
Share on other sites

Thank your very much!

You've been a big help to me!

When the project is finished, I will post it to 'SHOWCASE - Share what you've done'.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×