Jump to content
Search Community

Object lags behind

CryOfGaming test
Moderator Tag

Recommended Posts

Hello, i have a project running in html5 canvas.

 

Since i cannot tell anything about the project itself, i try to make it easy to understand with other stuff.

 

Lets call the first object A

and the second object B

 

Object A gets moved by the users mouse (i handled that without TweenLite) and object B should stay to the same relative position as object A.

Object A can rotate, when it rotates object B rotates around object A to get the same relative position. This all works perfectly.

 

This code gets called around 150 times a second to try bring object B to the target position at A.

 

TweenLite.to(this, 0.5, {x: this.targetX, y: this.targetY, })

 

(decreasing duration in this code will look bad, so when i make it on 0.1 its lags not a lot behind but it looks bad)

 

Now the problem i have is that object B lags behind as long object A is moving. When object A stops, object B has no problem to reach the target position but since object A is constantly moving, object B wont reach object A. 

 

I tried to make some picutres to make it understand it better:

 

Here you see object not moving - everything is good. Object B is in correct position1.png.1325c03133f4ee33eaebcb9fe7f0c62d.png

 

 

Now object A rotatet a bit around, object B followed. Also looks good ( think it also lags a bit behind, but since the rotation is not fast, its not noticable)

2.png.1e5c09e3bc0565e3436566cab3113504.png

 

 

 

 

But now object A starts speeding up to a higher constant speed - object B trys to follow with the code that gets called 150 times per second, but it looks like that: 3.png.c31c17769fd57b6532b8d6f86a98d2af.png

 

I hope i somehow made it understandable 😄

So basically everything is working, rotation is looking good (nvm that small lag cause of the low rotation speed) but as soon it speeds up, object B got a distance which wont go any closer.

 

Thank you for any help!

Link to comment
Share on other sites

Hi CryOfGaming!

 

We're happy to answer any GSAP-specific questions, but we don't have the resources to provide free general consulting. This sounds more like a logic problem. For mouse movement, I usually use a lerp-like animation.

 

See the Pen WNNNBpo by GreenSock (@GreenSock) on CodePen

 

 

Of course anyone is welcome to assist with that if they want to, but it's highly unlikely that you will get any type of response without a minimal demo.

 

I also noticed that you are using a deprecated syntax. Check out the migration guide.

 

 

  • Like 3
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.
×
×
  • Create New...