do something for 10 seconds

Blitz3D Forums/Blitz3D Programming/do something for 10 seconds

Rook - modifying the code I posted earlier it should stop now on the correct numbers although might look a little odd. There are many many ways of doing what you are after, it is possible to pre calculate how fast to spin the wheels initially, how much to decelerate them each frame and how long to do so for based on the numbers they start on and where you want them to end. But if you are after a quick and dirty solution perhaps what is below will help:



pit(0)=72
pit(1)=71
pit(2)=38
pit(3)=0
pit(4)=-40
pit(5)=-70
pit(6)=-69
pit(7)=-39
pit(8)=0
pit(9)=39

rol(0)=180
rol(1)=0
rol(2)=0
rol(3)=0
rol(4)=0
rol(5)=0
rol(6)=180
rol(7)=180
rol(8)=180
rol(9)=-180

ya(0)=-180
ya(1)=0
ya(2)=0
ya(3)=0
ya(4)=0
ya(5)=0
ya(6)=-180
ya(7)=-180
ya(8)=-180
ya(9)=180

dim wheelnumbertoendon(4)

wheelnumbertoendon(1)=Rnd(0,9)
wheelnumbertoendon(2)=Rnd(0,9)
wheelnumbertoendon(3)=Rnd(0,9)
wheelnumbertoendon(4)=Rnd(0,9)

dim TurnRate#(4)
;set the initial turnrate for the wheels randomly:
TurnRate#(1)=10.0+rnd(-3.0,3.0) ;degrees per frame to turn higher number mean faster initial spin.
;do the same for indexes 2-4
dim WheelMesh(4)
WheelMesh(1)=mesh
WheelMesh(2)=mesh2 ;this is using your already defined mesh/mesh2/mesh3/mesh4 entities but storing their handles in an array instead, easier to manipulate
WheelMesh(3)=mesh3
WheelMesh(4)=mesh4



Decay#=0.995  ;adjust to any value between 0.0 and 1.0 to change the rate at which they slow down, and therefore changing the amount of time taken for the wheels to come to rest.
repeat

HaveWheelsStopped=true
for i=1 to 4
turnentity WheelMesh(i),TurnRate#(i),0,0 ;only need to alter the pitch why bother altering the yaw and roll unless you are doing something totally different to what I am thinking you are
If TurnRate#(i)>=0.1 then TurnRate#(i)=TurnRate#(i)*Decay
if TurnRate#(i)<0.1 then 
;
;
;
;TurnRate#(i)=0
Tolerance#=2.0 ;degrees to allow either side of.
if entitypitch(WheelMesh(i))>pit(wheelnumbertoendon(i))-tolerance and entitypitch(wheelmesh(i))<pit(WheelNumbertoEndOn(i))+tolerance and entityyaw(wheelmesh(i))>ya(wheelnumbertoendon(i))-tolerance and entityyaw(wheelmesh(i))<ya(Wheelnumbertoendon(i))+tolerance and entityroll(wheelmesh(i))>rol(wheelnumbertoendon(i))-tolerance and entityroll(wheelmesh(i))<rol(wheelnumbertoendon(i))+tolerance then 
;perhaps check if the entityroll and yaw values are equal to 180 or 0 rather than use a tolerance if they are always 'exactly +-180 or exactly 0...
TurnRate#(i)=0 
;you could put a few lines in here that now actually set the yaw, pitch and roll of the wheel to the values in your arrays for pit(),ya() and rol() which will make the wheels jump those final few degrees to their correct position, as if they click into place, although it may look a little artificial.
endif 
;
;
endif 
if TurnRate#(i)<>0 then HaveWheelsStopped=false
next

renderworld
updateworld
flip
until HaveWheelsStopped=true or keydown(1)


There is an alternative way of doing this