Jump to content
Search Community

Update a running tween

gareth test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I am trying to increase the height of a jump performed by my character depending on how long the space bar is held down. 

 

I have a working demo here: 

 

What I don't understand how to do is to update the end point (and speed) of the tween once it is running. At the moment I have a double jump effect, but ideally I would like the height of the jump to increase with the length of the press.

See the Pen LEPqbE by eighthday (@eighthday) on CodePen

Link to comment
Share on other sites

Here's my version. This may or may not work for your circumstances. I didn't opt to use a Timeline. Instead I just repeatedly call the same function, adjusting the jumping Tween, while the spacebar is held.

 

There are probably a million valid ways to code this, but here's the version I threw together. Note that this would only work for completely flat surfaces since it Tweens y to 0 every time. Additional logic would have to be added to compensate for that.

 

See the Pen YPzPyd by maelfyn (@maelfyn) on CodePen

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