Code archives/Algorithms/SpeedLimit

This code has been declared by its author to be Public Domain code.

Download source code

SpeedLimit by Ratboy2003
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.
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
; FUNCTION SpeedLimit()
; returns a multiplier to reduce Xv & Yv by
; to keep mover speeds from going through the
; roof
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Function SpeedLimit#(SpeedX#,SpeedY#,TopSpeed#)

	Vector = Sqr(SpeedX * SpeedX + SpeedY * SpeedY)
	If Vector > TopSpeed Then
		Limiter# = TopSpeed / Vector
	Else
		Limiter# = 1
	EndIf
	
	Return Limiter

End Function

Comments

None.

Code Archives Forum