2D Collisions Help

Blitz3D Forums/Blitz3D Beginners Area/2D Collisions Help

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Sure! I must admit that I forgot about that circumstance!

All you have to do is change the bit that I labelled "The more complicated bit" to this:

		; The more complicated bit
		If gravity < 0
			Repeat
				If ImagesCollide(backimage,0,0,0,charimage,px,py,0)
					py=py-1
					jumping = False
					gravity = 0
				Else
					Exit
				EndIf
			Forever
		ElseIf gravity > 0
				Repeat

				If ImagesCollide(backimage,0,0,0,charimage,px,py,0)
					py=py+1
					gravity = 0
				Else
					Exit
				EndIf
			Forever
		EndIf



Oh, and by the way, I'm sure that this is not the only way to do what you want to do - it's just how I would do it! I'm sure someone else could offer a different approach.
But if it works...


Oh, and if you want more realistic physics, instead of setting gravity to zero with each collision, you could have it "bounce" by doing this:

		If gravity < 0
			Repeat
				If ImagesCollide(backimage,0,0,0,charimage,px,py,0)
					py=py-1
					jumping = False
					gravity = -gravity / 3
				Else
					Exit
				EndIf
			Forever
		ElseIf gravity > 0
				Repeat

				If ImagesCollide(backimage,0,0,0,charimage,px,py,0)
					py=py+1
					gravity = -gravity / 3
				Else
					Exit
				EndIf
			Forever
		EndIf