reset entity

Blitz3D Forums/Blitz3D Programming/reset entity

Well i have investigated ResetEntity and my advice is to avoid it if possible. I always thought resetentity was supposed to discard collisions and leave the entity at the original position it would have been at before updateworld. Now I must say I never used it much if at all, so maybe I am mistaken.

Anyway, I figure, Ok I will record the original position myself and apply that after resetentity. Which works well enough, except having moved on collisions are always reported for the collisionentity!

So then I figure maybe renderworld is sticking its oar in as well, so I set a flag to apply resetentity just before the next updateworld. Which seems to work, but is far from ideal.

My guess at this stage is either ResetEntity or my brain is broken.

Graphics3D 640,480,0,2

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


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

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

Collisions 2,1,2,1

Xspeed#=2
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)	

	If reset=True Then ResetEntity sphere : reset=False

	UpdateWorld	
	
	Colls=CountCollisions(sphere)
	
	For c=1 To colls
		
		If CollisionEntity(sphere,c)=cube Then
			CollX#=CollisionX(sphere,c)
			CollY#=CollisionY(sphere,c)
			CollZ#=CollisionZ(sphere,c)
			Reset=True; ResetEntity sphere
			PositionEntity sphere,OriginalX,OriginalY,OriginalZ

		EndIf
	Next
		
	RenderWorld
	
	Text 0,0,"Entity position "+EntityX(sphere)		
	
	If Colls>0 Then 
		Text 0,12,"Entity was reset following "+Colls+" collisions "
		Text 0,24,"at location  "+CollX+","+CollY+","+CollZ
	EndIf
	
	Flip
	
Until KeyDown(1)