Turrets

Blitz3D Forums/Blitz3D Beginners Area/Turrets

Crazy4Code(Posted 2005) [#1]
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?


big10p(Posted 2005) [#2]
Just use floats.


Crazy4Code(Posted 2005) [#3]
Wait, aren't floats just decimal numbers? And if they are, you can't move a fraction of a pixel can you?


Crazy4Code(Posted 2005) [#4]
I just tried using floats, but it just rounds to the nearest integer and does the same thing.


Who was John Galt?(Posted 2005) [#5]
Post some code.


Crazy4Code(Posted 2005) [#6]
What part? I know you can use decimals in 3D, but you know I'm talking 2D right?


octothorpe(Posted 2005) [#7]
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



Who was John Galt?(Posted 2005) [#8]
^^ What he said!


Crazy4Code(Posted 2005) [#9]
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.


Who was John Galt?(Posted 2005) [#10]
Yes, but the thing will move at fractional speeds. i.e: if vx is 0.5, it moves 1 whole pixel every 2nd frame.


Crazy4Code(Posted 2005) [#11]
Oh, I see how that works, I think this is what I need. Thanks!