2D Smooth Turning in a Tile-Based Game

Posted by ApoorvaJ on Game Development See other posts from Game Development or by ApoorvaJ
Published on 2012-12-08T19:25:02Z Indexed on 2012/12/08 23:37 UTC
Read the original article Hit count: 251

Filed under:
|

I am working on a 2D top-view grid-based game. A ball that rolls on the grid made up of different tiles. The tiles interact with the ball in a variety of ways.

I am having difficulty cleanly implementing the turning tile. The image below represents a single tile in the grid, which turns the ball by a right angle.

Turning tile

If the ball rolls in from the bottom, it smoothly changes direction and rolls to the right. If it rolls in from the right, it is turned smoothly to the bottom. If the ball rolls in from top or left, its trajectory remains unchanged by the tile.

The tile shouldn't change the magnitude of the velocity of the ball - only change its direction.

The ball has Velocity and Position vectors, and the tile has Position and Dimension vectors.

I have already implemented this, but the code is messy and buggy. What is an elegant way to achieve this, preferably by modification of the ball's Velocity vector by a formula?

© Game Development or respective owner

Related posts about math

Related posts about 2d-physics