Jump to content
Search Community

Bouncing Ball Y and X

o3digital test
Moderator Tag

Recommended Posts

Hi,

Inspired by the bouncing ball demo with custom bounce, I try make the ball bounce on the "right wall".

After I need the ball finish is translation in the middle of the screen.

When the container "#playground" width is near to 1280 px it is quite good but when I reduce the width to 480 px the ball is going to far and not in the middle of the playground.

I 'm not sure to well understand the custom bounce...

 

Please a little help ?

Thomas

 

See the Pen LYeqvQm by omicronn (@omicronn) on CodePen

Link to comment
Share on other sites

The bouncing is only on the y-axis. You can simply adjust where the "x" value is going. That means calculating how far it has to move on the x-axis to hit that "wall" that you're talking about. Probably use getBoundingClientRect() to do those calculations. 

 

Good luck!

Link to comment
Share on other sites

Sorry, it's beyond the scope of help we can provide in the forums to finesse your animation timing, easing, etc. to make it look more realistic. Perhaps you're looking for a physics library? GSAP is generally for animating from certain values to others, with easing applied. It's not intended to do something like "apply physics and make it look like the div is bouncing off the wall and lands perfectly in a pre-determined spot, including squash and stretch". You can certainly get a good-looking result with enough tweaking of the values.

 

Good luck!

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...