Sign in to follow this  
burgero

SDL Angular Movement

Recommended Posts

Hello,

I'm new to game programming and I am currently working a 2D Sidescroller using SDL. I'm attempting to make a function that will move an object from point A to point B in a straight line at a fixed speed...so if the speed is set to 5 then it will move 5 pixels across the line each frame.

Things are looking pretty good, but I am running into an issue if the slope of the line is extreme. If I have a point located at (0,0) and another located at (3,30), and I want to move at a speed of 5 pixels a frame. The issue I have is that because I can't do decimals in SDL_Rect I get a sort of staircase like movement. Does anyone have any suggestions to keep the movement in a smooth straight line, or am I out of luck?

Share this post


Link to post
Share on other sites
[quote name='Wooh' timestamp='1313799669' post='4851441']
Easiest way is probably to store the positions as floating point numbers (float or double).
[/quote]
It would not help if you don't turn on multi-sampling, but it is not that which is the problem. You should use floats to calculate the vector between the points, then convert the numbers to int, if you cast it would round off to the lowest nearest number. It may not be what you want. Use ceil function if you want to round up or use floor to round down.

Share this post


Link to post
Share on other sites
I got it to look a lot better, thanks. For all my calculations I made sure to store the points as floats, and then right I showed the image I casted them to ints.

Another issue I was having was with my calculations....Every frame the equation of the line to move on was re-calculating, which was causing some bad looking movement. I made sure that my image moved along the same line until it reached its destination, and this made things look a lot better.

Thanks for your replies!

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

Sign in to follow this