Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
jeroen.delau

Combining 2DPath and 2D Physics

Recommended Posts

Hey! I'm trying to get 2DPhysics and 2DPath plugins to work together. But when I run the code nothing moves. The code commented out is working, I just want to add the physics to it.

var time:int;
var length:Number;
			
_moving = false;
_animation = false;
			
_path = new LinePath2D(getPoints());
length = _path.totalLength;
if(!_time){
	_time = length / _speed;
}
_path.addFollower(this.entity);
//_activeTween = TweenLite.to(_path, _time, {
				
//	progress:1, 
//	ease:Power0.easeOut,
//	onComplete: onComplete
//});
			
_activeTween = TweenLite.to(_path, _time, {physics2D:{velocity:0, angle:90, acceleration:200, friction:0}, onComplete:onComplete});
Link to comment
Share on other sites

I found the problem! Stupid mistake, I forgot to add progress: 1, to the new statement. However, I'm currently encountering a new issue. Quite frequently the tween "over shoots". With the entities entities ending up beyond the prescribed path.

Link to comment
Share on other sites

Those concepts are mutually exclusive. In other words, physics2D would need to control x/y properties in a specific way and yet the LinePath2D also controls them, but not in the same way. You could certainly tween the "progress" in a physics-based way I suppose, but as you discovered that means you're at the mercy of physics in terms of where/when it lands, although you could tweak the acceleration/friction/velocity values to try to get it just right. If your goal is to start at a specific velocity and then drift to a stop, ThrowPropsPlugin may be exactly what you're looking for, and it allows you to define a specific stopping point to ensure there's no "overshoot". 

  • Like 1
Link to comment
Share on other sites

Hmm, that is a bit of a bummer. I'm aiming to achieve a drop like effect. Start from stand still, accelerate to a max velocity, complete stop when the end of the path is reached. For ease of understanding, imagine Candy Crush dropping candy.

 

The path2D is working beautifully, but I can't get the right easing effect to mimic the gravity. Essentially it needs to accelerate to a constant speed and then stay level. Should I write a custom easing function instead?

Link to comment
Share on other sites

When you said "accelerate to a constant speed and then stay level", I instantly thought of just using a regular tween with ease:Linear.easeNone but start it with a timeScale of 0.0001 (or something really small) and then use ANOTHER tween to tween that tween's timeScale to 1, thus it appears to accelerate. Kinda like:

var tween = TweenLite.to(....{ease:Linear.easeNone});
tween.timeScale(0.0001);
TweenLite.to(tween, 1, {timeScale:1, ease:Power1.easeIn});

Just an idea. 

  • Like 1
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.
×