If you re-wrote this line in, more or less, English, what would it say?
If CountCollisions (cube) = .01 To .1 Then MoveEntity sphere,.1,0,0 Step .01
;If the number of times that the cube has Collided with something is equal to
;1/100th To 1/10th, Then move the sphere 1/10th to the right, Stepping by 1/100th
It doesn't seem to make a lot of sense, even in English. The "To" and the "Step" commands should only be used in a For...Next loop. Specifically, "To" should be used like:
For x = 1 To 100 ;Do this part 100 times. "To" is used to identify the maximum
Print "This is number " + x
Next
"Step" can be used like this:
For x = 1 To 100 Step 10 ;Do this part only ten times now because "Step" tells blitz to skip by 10's each pass
Print "This is number " + x
Next
CountCollisions() will return the number of times your entity collided with something else since the last UpdateWorld was called. You can use this number when you're looking for a specific collision point, but you have no idea before hand where or when this collision will take place. Typically, I have little use for this command, but other programmers use it quite often. Instead, I prefer to use EntityCollided() to know if my specific entity has hit another type of entity. For what you're asking, this is probably what you're looking for.
Going back to your original line of code, this is how I would write it to do the things you were wanting, including the going from point A to point B stuff. This is not a demo and will not display results in its current state. All of the code is related to the task mentioned above.
Const TYPE_CUBE = 1 ;Make a collision type for the cube
Const TYPE_TRIGGER = 2 ;Make a collision type for the trigger
Global cube = CreateCube() ;Create a cube
EntityType cube,TYPE_CUBE ;Make cube the TYPE_CUBE
Global trigger = CreateSphere() ;Create a sphere, or a 'trigger'
EntityType trigger,TYPE_TRIGGER ;Make the trigger TYPE_TRIGGER
Collisions TYPE_CUBE,TYPE_TRIGGER,2,3 ;Check for collisions between them
;MAIN LOOP HERE
While Not KeyDown(1)
;The next three lines are the way you would want to write your original line posted
If EntityCollided(cube,TYPE_TRIGGER) ;If the cube has collided with TYPE_TRIGGER
WarpToNewLocation(cube,0.1,0,0) ;Warp to a new location (found below)
EndIf
UpdateWorld
RenderWorld
Flip
;END MAIN LOOP HERE
Wend
;Functions lists
Function WarpToNewLocation(entity,x#,y#,z#) ;This will gradually move an entity to a point in space
Local continue = 0
While continue = 0 ;There's other ways to do this, but I picked using an internal loop
;Please note that I am horrible with the TForm commands, but this would
;be the perfect spot to use those. This is my method, but eventually, I'm
;going to move towards using the TForm commands in place of all of this
;junk.
Local TempPitch# ;Make a temporary variable to store pitch values
Local TempYaw# ;Make a temporary variable to store yaw values
Local TempRoll# ;Make a temporary variable to store roll values
Local TempPivot ;Make a temporary variable to attach a tempory pivot to
TempPitch# = EntityPitch(entity) ;Get the current pitch of the entity
TempYaw# = EntityYaw(entity) ;Get the current yaw of the entity
TempRoll# = EntityRoll(entity) ;Get the current roll of the entity
TempPivot = CreatePivot() ;Create a temporary pivot
PositionEntity TempPivot,x#,y#,z# ;Position the pivot at the new location
PointEntity entity,TempPivot ;point the entity at the pivot (new location)
MoveEntity entity,0,0,0.5 ;Move the entity in a positive Local Z Direction
If EntityDistance(entity,TempPivot) < 2 ;If the entity is close to the new location...
continue = 1 ;Break the While...Wend loop
EndIf
RotateEntity entity,TempPitch#,TempYaw#,TempRoll# ;Rotate the entity back to how it was originally facing
FreeEntity TempPivot ;Save memory and get rid of the temporary pivot
UpdateWorld
RenderWorld
Flip
Wend
End Function
|