follow path

BlitzMax Forums/BlitzMax Beginners Area/follow path

No, it was an error on my side, because I missed 2 things:

1. You need to define a length in which the spring does not push or pull
2. I gave you the formula for the spring energy, not force


Here is the working one, sorry for making headache


Strict


Graphics 800,600


Global jposx
Global jposy


Global Satellites_list:TList = CreateList()

Type TSatellite

	Field x#
	Field y#
	Field SpeedX#
	Field SpeedY#

	
	Function Create:TSatellite (x:Int, y:Int)
	
		Local n:TSatellite = New TSatellite
		
		n.x# = x
		n.y# = y
		
		ListAddLast Satellites_list, n
		
		Return n
	
	End Function
	
	Function Update()
	
		
		Local Weight# = 5.0
		
		Local k# = 0.01
		Local spring_neutral_length# = 8.0
	
		For Local s:TSatellite = EachIn Satellites_list
		
			Local dx#	= s.x - Float(jposx)
			Local dy#	= s.y - Float(jposy)
			
			Local ForceX# = (spring_neutral_length-dx) * k
			Local ForceY# = (spring_neutral_length-dy) * k 
			
			Local AccelerationX# = Float(ForceX# / Weight#)
			Local AccelerationY# = Float(ForceY# / Weight#)
			
			s.SpeedX# = s.SpeedX# + AccelerationX#
			s.SpeedY# = s.SpeedY# + AccelerationY#
			
			s.x# = s.x# + s.SpeedX#
			s.y# = s.y# + s.SpeedY#
			
			DebugLog s.x
			DebugLog s.y
			
			SetColor 255,0,0
			DrawOval s.x,s.y, 20,20
			
		Next
	
	End Function

End Type

While Not KeyDown(KEY_ESCAPE)
	
		Cls
		jposx = MouseX()
		jposy = MouseY()
		SetColor 255,255,255
		DrawOval MouseX(), MouseY(), 10,10
		TSatellite.Update()
		
		If MouseDown(1) Then
			Local s1:TSatellite = TSatellite.Create (MouseX()+10, MouseY()+10)
			FlushMouse()
		End If
		
		Flip
Wend