Monday, March 26, 2007

Rotation works... Finally...

Ok, so I finally managed to fix all the weird shit concerning rotation and movement. The large break from coding really helped on that.

Basically, what I did was this: I ditched all my previous movement and rotation code. I then re-build everything up from the ground using sheer logic. It was actually pretty easy.

I did make the same mistake I made the first time with my movement code. I rounded the location X and Y to an integer value(they're stored as floats). So, when a unit would move to x.86, it would round to x + 1, which obviously is somewhat correct. However, if I would start moving from this location, the angle wouldn't be correct anymore, and the unit would just move over a bunch of tiles it wasn't suppose to be on. I noticed this when I would start printing out the x,y locations after movement. Easily fixed.

After that, my rotation code was simple. The old code was overly complicated, while my current code(Including determination of which direction to turn in) is something like 20 lines.

Now I only need to re-work this code so that it also works for the turret, and the problem is solved. Then turretted buildings/units can share the same code.

So, later today I'll start adding weapons. I think I'll start out with the medium tank, since it's the coolest tank of all(coolest graphics, I have no idea why).

No images for now, perhaps after I got some weapons in.

1 comment:

Fundynamic - Stefan Hendriks said...

I am not sure how you do your rotation.

What i did was keep 8 sides in memory. And just store that.

For my new engine, i store 256 'angles'.

If you mean "convert an x,y delta to an angle" code, then i can see your problem. Though even then it is not that super hard.

As i said, i don't know how your code is, so it got messed with floats.

Good to read its fixed.