Hi All,
I have a little problem with a program I have created to move a sprite in a circle around a centre point. When the angle reaches 360 degrees I would lile the angle to reset to 0 and start again. Adjusting the speed of the rotation sometimes causes the If condition to be missed due to floating point inacuracy.
i,e If S\SA#=360 Or S\SA#=360 Then S\SA#=0
Function below usng types, any Ideas,
Function updateships()
For s.ship = Each ship
Local shipx#, shipz#
;update shipangle# and maintain speed at different distances
S\SA#=S\SA#-(S\SP#/S\SD#)
If S\SA#=360 Or S\SA#=-360 Then S\SA#=0
;Update position around radius using the sin/cos functions
shipx# = S\SCX# + ( Cos#(S\SA#) * S\SD# )
shipz# = S\SCZ# + ( Sin#(S\SA#) * S\SD# )
;draw the ship
PositionEntity S\SIMAGE,shipx#,S\SY#,shipz#
RotateEntity S\SIMAGE,0,(S\SA#-90),0
If S\SID%=0 Then
SNAME1=S\SNAME
SA1#=S\SA#
SX1#=shipx#
SZ1#=shipz#
SSP1#=S\SP#
End If
Next
End Function
I have a little problem with a program I have created to move a sprite in a circle around a centre point. When the angle reaches 360 degrees I would lile the angle to reset to 0 and start again. Adjusting the speed of the rotation sometimes causes the If condition to be missed due to floating point inacuracy.
i,e If S\SA#=360 Or S\SA#=360 Then S\SA#=0
Function below usng types, any Ideas,
Function updateships()
For s.ship = Each ship
Local shipx#, shipz#
;update shipangle# and maintain speed at different distances
S\SA#=S\SA#-(S\SP#/S\SD#)
If S\SA#=360 Or S\SA#=-360 Then S\SA#=0
;Update position around radius using the sin/cos functions
shipx# = S\SCX# + ( Cos#(S\SA#) * S\SD# )
shipz# = S\SCZ# + ( Sin#(S\SA#) * S\SD# )
;draw the ship
PositionEntity S\SIMAGE,shipx#,S\SY#,shipz#
RotateEntity S\SIMAGE,0,(S\SA#-90),0
If S\SID%=0 Then
SNAME1=S\SNAME
SA1#=S\SA#
SX1#=shipx#
SZ1#=shipz#
SSP1#=S\SP#
End If
Next
End Function