New Star Soccer 4

BlitzMax Modules Forums/MiniB3D/New Star Soccer 4

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.

SimonH, I'm getting some issues with collisions between the ball and the goalpost/crossbar. Basically I handle the collision like so...

If matchengine.enginestatus <> CENGINESTATUS_REPLAYING	' Don't do collisions during replays
			Local bounce:Float = 0.0
			Local NFx:Float = 0.0
			Local NFy:Float = 0.0
			Local NFz:Float = 0.0
			
			For Local i:Int = 1 To CountCollisions(mesh)
				
				Local myentity:TEntity = CollisionEntity(mesh, i)	' TEntity
					
				' Get the normal of the surface which the entity collided with. 
				Local Nx# = CollisionNX(mesh, i) 
				Local Ny# = CollisionNY(mesh, i) 
				Local Nz# = CollisionNZ(mesh, i) 
				
				' Compute the dot product of the entity's motion vector and the normal of the surface collided with. 
				Local VdotN# = vecVelocity.x*Nx# + vecVelocity.y*Ny# + vecVelocity.z*Nz#
				
				Select GetEntityType(myentity)
					Case CTYPE_GOALPOST
						Applog "Collision GoalPost"
						bounce = 0.8
						' Calculate the normal force. 
						NFx = -(2.0) * Nx# * VdotN# 
						NFy = -(2.0) * Ny# * VdotN# 
						NFz = -(2.0) * Nz# * VdotN#
						
						
					Case CTYPE_GOALNET
						Applog "Collision GoalNet"
						' Only bounce off net if post wasn't hit
						If bounce = 0 and (GetZ() > matchengine.GoalLine1 or GetZ() < matchengine.GoalLine2)
							NFx = -(2.0) * Nx# * VdotN# 
							NFy = -(2.0) * Ny# * VdotN# 
							NFz = -(2.0) * Nz# * VdotN# 
							
							'  Normal slight bounce
							bounce = 0.2
							EndIf
					Case CTYPE_WALL
						Applog "Collision Wall"
						If bounce = 0 
							bounce = 0.6
							NFx = -(2.0) * Nx# * VdotN# 
							NFy = -(2.0) * Ny# * VdotN# 
							NFz = -(2.0) * Nz# * VdotN# 
						EndIf
						
					Case CTYPE_STADIUM
						Applog "Collision Stadium"
						If bounce = 0 
							bounce = 0.6
							NFx = -(2.0) * Nx# * VdotN# 
							NFy = -(2.0) * Ny# * VdotN# 
							NFz = -(2.0) * Nz# * VdotN# 
						EndIf
				End Select
				
			Next
			
			If bounce > 0
				Local mx:Float  = ((vecVelocity.x + NFx#) * bounce)
				Local my:Float  = ((vecVelocity.y + NFy#) * bounce)
				Local mz:Float  = ((vecVelocity.z + NFz#) * bounce)
				
				vecVelocity.x = mx
				vecVelocity.y = my
				vecVelocity.z = mz
			EndIf
		EndIf


The bounce check is purely to try to force the game to deal with primarily the goalpost collision in one loop rather than deal with a clash between ball, goalpost and goalnet.
However, I'm occasionally seeing the ball change direction two or three times in one collision with the goal frame.