unwanted collision occurring

BlitzPlus Forums/BlitzPlus Beginners Area/unwanted collision occurring

Hi folks, haven't posted in ages, but I'm hoping I can get some help with this collision problem. In my game, I have sprites advancing towards each other, walking down the pavement towards each other. At one point, one of the sprites goes Postal, and hits the other sprite. At that point, I put in a "hotspot" on the Postal sprite ( his fist ), to detect if he's landed a punch on the other dude. Trouble with my code is, it seems to be detecting the collision between the "hotspot" and the "victim" even when I haven't drawn the hotspot to the screen, so even when the first sprite hasn't done anything, the second sprite reacts...

I have used "ImagesOverlap" but the problem is the same with "ImagesCollide"...

I have some B+ code which illustrates my problem...

thanks for your attention, and I hope it isn't something laughably simple that will make me look like an idiot :)

Graphics 800,600

;boolean to report a collision
Global CollisionDetected=False

;variables for timing
Global	DeltaTime#,OldMillisecs#,ThisTime#

;variables For positioning the sprites
Global Sprite01X=-100,Sprite01Y=400,Sprite02X=900,Sprite02Y=400

;creating sprite one
Global Sprite01=CreateImage(64,128)
SetBuffer ImageBuffer(Sprite01) 
Color 255,102,102
Rect 0,0,64,128,1
Color 0,0,0
Rect 16,80,32,48
Rect 50,20,5,5,1
Line 40,35,64,40

;creating sprite two
Global Sprite02=CreateImage(64,128)
SetBuffer ImageBuffer(Sprite02) 
Color 102,153,255
Rect 0,0,64,128,1
Color 0,0,0
Rect 16,80,32,48
Rect 14,20,5,5,1
Line 24,35,0,40

;creating a "hotspot"
Global HotSpot=CreateImage(32,32)
SetBuffer ImageBuffer(HotSpot) 
Color 255,255,255
Rect 0,0,32,32,1

SetBuffer BackBuffer()

While Not KeyHit(1);main loop

	ThisTime#=MilliSecs()
	DeltaTime#=ThisTime#-OldMillisecs#
	OldMillisecs#=ThisTime#
	UpdateSprite01();draw the sprites
	UpdateSprite02();draw the sprites
	If ImagesOverlap(HotSpot,Sprite02X,Sprite02Y+20,Sprite01,Sprite01X,Sprite01Y)
		CollisionDetected=True
	EndIf	
	Color 51,153,0;ground colour
	Rect 0,528,800,72,1;draw the ground	
	Color 0,0,0;text colour	
	If CollisionDetected;report if a collision has occured between sprite and "hotspot"
		Text 350,550,"COLLISION DETECTED"
	Else
		Text 350,550,"NO COLLISION DETECTED"
	EndIf
	Text 10,580,"ESC to quit"
	Flip()
	Cls()

Wend

End

Function UpdateSprite01()


	Sprite01X=Sprite01X+(0.05*DeltaTime)
	If Sprite01X>900;reset sprite position
		Sprite01X=-100
		CollisionDetected=False;reset detection boolean
	EndIf	
	DrawImage Sprite01,Sprite01X,Sprite01Y

	
End Function

Function UpdateSprite02()
	
	Sprite02X=Sprite02X-(0.05*DeltaTime)
	If Sprite02X<-100 Sprite02X=900;reset sprite position
	DrawImage Sprite02,Sprite02X,Sprite02Y
	;DrawImage HotSpot,Sprite02X,Sprite02Y+20

End Function



It doesn't matter if you draw the hotspot on the screen as long as you use imagesoverlap, it assumes that you drew the images on the screen but this is not a requirement.

I would recommend only using images overlap if the player is currently punching otherwise skip that command.

If PlayerPunch = 1 Then
     If ImagesOverlap(bla bla bla you get the point)
EndIf



it assumes that you drew the images on the screen but this is not a requirement.


oh dear !


If ImagesOverlap(bla bla bla you get the point)



I do!

thanks Nate, I will rework my code :)

You are welcome

Please tell me if it works :)

it worked immediately :)