Jump to content
  • Advertisement
lifesuxtr

How to make a top down 2D ball rolling

Recommended Posts

14 hours ago, lifesuxtr said:

For example if this is our ball texture:

q9UMP.png

 

That doesn't look like any billiards ball I've ever seen :) 

But also note that you cannot map a rectangular texture to a sphere. However in the case of billiards balls you might be able to get away with cylindrical projection because at the poles it's just one color. You then likely want to use orthographic projection which maps easily to screen coordinates and matches the 2D playing field.


There's also the problem of aliasing. In 3D you get jagged edges by default - especially visible on small objects - where sprites offer you full control over the alpha channel.

In the end I don't think it's really worth the effort.

Share this post


Link to post
Share on other sites
Advertisement

Can you draw your sprites using a shader? There is a trick you can use to take a 2D image map and make it look like it's mapped on a sphere. It's detailed here as relating to drawing the resource bubble graphics in Diablo 3. (I have a demo of that in a github repo here). The gist of it is that you use a texture like this:

normaltex.png

Then use that to distort the UV coordinates mapped across the sprite, then use these distorted coordinates to sample the ball texture. So your ball texture then might look something like this:

KllJGXW.png

If the texture is seamless, then you can animate the UV coordinates linearly to make it appear the ball is rolling in a given direction; change the direction of the UV scroll to change the apparent direction of the roll.

43X7dDj.gif

Share this post


Link to post
Share on other sites
1 hour ago, lifesuxtr said:

@JTippetts this looks like the best solution i guess. Now i need to find how to scroll texture on libGDX  :D

The scrolling should just happen inside the shader, by adding an offset based on time and speed to the UV coordinates. The offset is a vec2, and you would calculate it outside the shader based on the negative of the ball's movement direction. You could also specify a 'spin' speed as well, and apply a rotation of the UV coordinate in the vertex shader to simulate balls that are spinning around the vertical axis in addition to rolling.

Share this post


Link to post
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!