# 2d Game Edge Bouncing Effects

This topic is 2761 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've recently been experimenting and attempting to recreate an iOS UI sort of edge bouncing effect in my game so that if you scroll past a level's boundaries, the camera slowly bounces back to the boundary.

At the moment I've implemented some of Robert Penner's tweening calculations ported from ActionScript, however I'm unsure whether this is the correct approach due to the fact that it doesn't take into account our camera's velocity. At the moment it looks something like this:

 easeInOut(currentTime, startValue, endValue, duration); 

The actual implementations are available here: http://www.jesusgollonet.com/blog/2007/09/24/penner-easing-cpp/

I've come to the conclusion that this is a sort of grey area as I haven't been able to find much information on it, either that or I'm not familiar with the correct name for the sort of calculation I'm attempting to describe. If anyone has any advice, or solutions that include velocity in their games or UI's, I'd be very interested to hear it!

##### Share on other sites
A simple solution would be to move the camera a percentage of the distance back to the boundary each step; that is, if the camera is off the level on the left, each step add a*(leftBoundary - cameraPosition) to cameraPosition, where a is a tunable constant between 0 and 1. Steps happen very quickly, so a will probably be a lot closer to 0 than to 1. If your timesteps are of variable length, you'll need to adjust a each timestep to get a consistent appearance. I don't know your mathematical background; if you need help with that please say.

The bounce-back speed is calculated each step from the position, so if the user scrolls while the camera is already sliding back, the speed changes automatically. If I'm understanding your camera velocity issue correctly, then, it shouldn't be a problem for this method.

##### Share on other sites
Thanks for the insight, I had a suspicion that the most managable way to achieve this was on a frame by frame basis, I have a fixed timestep already, so that much is covered. I'm going to implement your solution on Monday after which I'll share my results on here! Thanks again!

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 12
• 9
• 11
• 15