October 28, 2021, 11:32:51

Author Topic: [bb] SpeedLimit by Ratboy [ 1+ years ago ]  (Read 567 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] SpeedLimit by Ratboy [ 1+ years ago ]
« on: June 29, 2017, 00:28:42 »
Title : SpeedLimit
Author : Ratboy
Posted : 1+ years ago

Description : This is most useful in an Asteroids Physics environment. To use SpeedLimit(), pass the X & Y components of your vector along with your preferred top speed to SpeedLimit(), and multiply the result against SpeedX and SpeedY.

Code :
Code: BlitzBasic
  1. ;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  2. ; FUNCTION SpeedLimit()
  3. ; returns a multiplier to reduce Xv & Yv by
  4. ; to keep mover speeds from going through the
  5. ; roof
  6. ;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7. Function SpeedLimit#(SpeedX#,SpeedY#,TopSpeed#)
  8.  
  9.         Vector = Sqr(SpeedX * SpeedX + SpeedY * SpeedY)
  10.         If Vector > TopSpeed Then
  11.                 Limiter# = TopSpeed / Vector
  12.         Else
  13.                 Limiter# = 1
  14.         EndIf
  15.        
  16.         Return Limiter
  17.  
  18. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal