Turrets
Blitz3D Forums/Blitz3D Beginners Area/Turrets
| ||
I have this turret on top of a base (and I'm talking 2D here) and I need it to shoot different directions depending on how it's rotated. But since there's 45 rotations and you can't do fractions of movement, I need a way that the amount it moves on the x coordinate changes slightly instead of an entire pixel per frame. I could also just make less rotations, but it wouldn't control or look as nice. Anyone know a good way to do this? |
| ||
Just use floats. |
| ||
Wait, aren't floats just decimal numbers? And if they are, you can't move a fraction of a pixel can you? |
| ||
I just tried using floats, but it just rounds to the nearest integer and does the same thing. |
| ||
Post some code. |
| ||
What part? I know you can use decimals in 3D, but you know I'm talking 2D right? |
| ||
Graphics 800, 600 SetBuffer BackBuffer() x# = 400 y# = 300 dir = 20 vx# = Sin(dir) vy# = Cos(dir) While Not KeyHit(1) x = x + vx y = y + vy Cls Plot Int(x), Int(y) ; int() is redundant, but there to show you when the floats are converted to integers Flip Wend |
| ||
^^ What he said! |
| ||
But, if a float is converted to an integer, wouldn't it just be a whole number? Like, 4.6 would be converted to 5? I'll try it anyways. |
| ||
Yes, but the thing will move at fractional speeds. i.e: if vx is 0.5, it moves 1 whole pixel every 2nd frame. |
| ||
Oh, I see how that works, I think this is what I need. Thanks! |