reset entity

Blitz3D Forums/Blitz3D Programming/reset entity

Ok, a bit more investigation, and I think ResetEntity is OK. Don't know how I got the idea it reset the entity position, though I am still not sure what was occuring in my sample above.

Anyway your shoot through issue, here is another idea. What you can do is have a different entitytype for the water and the underlying surface. You also have two different entitytypes defined for the bullet. You set up your collisions so the main type collides with the water and the underlying surface etc. The other type will only collide with the underlying surface and whatever else you want. When you detect a collision with the water you change the entitytype so now the bullet will only collide with the underlying surface and whatever else you want. This still has the issue though that following a water collision a bullet to something other than water collision will not be detected until the next movement phase. This may not matter too much though.

BTW to post code use (code).. (/code) or (codebox) ...(/codebox) as below, but replace the () with []

Graphics3D 640,480,0,2

Cube=CreateCube()
EntityColor cube,0,0,255
EntityAlpha cube,0.5
ScaleMesh cube,0.1,10,10
RotateEntity cube,0,0,15
EntityType cube,1

Cube2=CopyEntity(cube)
EntityColor Cube2,255,255,0
EntityAlpha cube2,1
TranslateEntity cube2,-3,0,0
EntityType cube2,2

Sphere=CreateSphere()
EntityColor sphere,255,0,0
PositionEntity sphere,9.5,0,0
EntityType sphere,9

Cam=CreateCamera()
PositionEntity Cam,0,0,-15
PointEntity cam,cube

Collisions 9,1,2,1
Collisions 9,2,2,1
Collisions 8,2,2,1

Xspeed#=15
YSpeed#=0.1

Repeat

	TranslateEntity sphere,(KeyHit(205)-KeyHit(203))*Xspeed,(KeyDown(200)-KeyDown(208))*Yspeed,0

	OriginalX#=EntityX(sphere)
	OriginalY#=EntityY(sphere)
	OriginalZ#=EntityZ(sphere)	

	UpdateWorld
	

	Colls=CountCollisions(sphere)
	If colls=0 Then EntityType sphere,9
	For c=1 To colls
		Collent=CollisionEntity(sphere,c)
		If Collent=cube Then				
			CollX#=CollisionX(sphere,c)
			CollY#=CollisionY(sphere,c)
			CollZ#=CollisionZ(sphere,c)
			EntityType sphere,8
			PositionEntity sphere,OriginalX,OriginalY,OriginalZ
		EndIf
	Next
		
	RenderWorld
	
	Text 0,0,"Entity position "+EntityX(sphere)		
	
	If Collent=cube Then 
		Text 0,12,"Collision with water at location  "+CollX+","+CollY+","+CollZ
	EndIf
	If collent=cube2 Then
		Text 0,12,"Collison with other surface at location "+CollX+","+CollY+","+CollZ
	EndIf
	
	Flip
	
Until KeyDown(1)


Oh and another option here of course is to just parent or shadow the bullet with a pivot that can only collide with water, which should have occured to me before I got sidetracked by the intricacies of ResetEntity, and which should be ideal for you since the bullet will be entirely uneffected by the water transition. I have changed the order of things here as well which seems to better suit the finnicky ResetEntity command, though as your water transition will presumaby be a one time deal you can just free the pivot.

Graphics3D 800,600,0,2

outsize=20
Dim out$(outsize)

Cube=CreateCube()
EntityColor cube,0,0,255
EntityAlpha cube,0.5
ScaleMesh cube,0.1,10,10
RotateEntity cube,0,0,15
EntityType cube,1

Cube2=CopyEntity(cube)
EntityColor Cube2,255,255,0
EntityAlpha cube2,1
TranslateEntity cube2,-3,0,0
EntityType cube2,2

Sphere=CreateSphere()
EntityColor sphere,255,0,0
PositionEntity sphere,9.5,0,0
EntityType sphere,9
Pivot=CreatePivot(sphere)
EntityType pivot,8

Cam=CreateCamera()
PositionEntity Cam,2,0,-15
PointEntity cam,cube

Collisions 8,1,2,1
Collisions 9,2,2,1

Local Xspeed#=6, YSpeed#=0.1

Repeat

	Xmove=KeyDown(205)-KeyDown(203)
	Ymove=KeyDown(200)-KeyDown(208)
	
	If KeyDown(57) Then PositionEntity sphere,9.5,0,0
		
	For c=1 To CountCollisions(pivot)
		Collent=CollisionEntity(pivot,c)
		If Collent=cube Then
			CollX#=CollisionX(pivot,c)
			CollY#=CollisionY(pivot,c)
			CollZ#=CollisionZ(pivot,c)
			output=output+1 : If output>outsize Then output=1
			out(output)="Collision with water at location  "+CollX+","+CollY+","+CollZ
			PositionEntity pivot,0,0,0
			ResetEntity pivot
		EndIf
	Next	

	For c=1 To CountCollisions(sphere)
		Collent=CollisionEntity(sphere,c)
		If Collent=cube2 Then
			CollX#=CollisionX(sphere,c)
			CollY#=CollisionY(sphere,c)
			CollZ#=CollisionZ(sphere,c)
			output=output+1 : If output>outsize Then output=1
			out(output)="Collison with other surface at location "+CollX+","+CollY+","+CollZ
		EndIf
	Next
	
	TranslateEntity sphere,Xmove*Xspeed,Ymove*Yspeed,0

	UpdateWorld
	RenderWorld

	y=0
	start=output-12 : If start<1 Then start=1
	For i=start To output
		Text 0,y,out(i) : y=y+12
	Next		
	
	Flip
	
Until KeyDown(1)