reset entity

Blitz3D Forums/Blitz3D Programming/reset entity

D4NM4N(Posted 2005) [#1]
This is some thing that has been driving me nuts for 2 years and never got to the bottom of!!
I thought resetentity reset the collision state of a entity before a pass to updateworld.
I want a bullet that hits the water to not stop, just the detection to be registered to create a splash, then be reset so it can carry on.

No joy. it just sits there sunbathing for x number of frames before getting forced through.

i can hide the entity with a latch variable for 1 or 2 frames, but that is annoying and (should? be unnecassary??)

please someone scratch this itch that needed scratching ages ago, before i go mad.


jfk EO-11110(Posted 2005) [#2]
It's very simple. Move the bullet and store its xyz position before the updateworld. then perform updateworld and check for collision. if it collided, hide it, position it at the stored xyz coords, then unhide it again, there you go.


D4NM4N(Posted 2005) [#3]
Thats pretty much how ive always got round it. :)
My main gripe is that i would like to know how to use resetentity as it looks useful but the help is not good. I cant seem to get it to do anything.


DJWoodgate(Posted 2005) [#4]
You use it after Updateworld.


D4NM4N(Posted 2005) [#5]
but once the code has looped it is after updateworld.
It doesnt seem to clear the collision state, it still stays stopped on the collided entity, or is it not supposed to prevent this.


DJWoodgate(Posted 2005) [#6]
You are right, it is not the way I remember it working. I will have to investigate a bit more.


D4NM4N(Posted 2005) [#7]
hmmm, got problems now. my latch system worked ok except for shallow water.
Ive come up with a way of cancelling the collision by hiding the entity for 1 frame, but it is moving so fast, the next frame sees it off. JFKs idea was tried too but when positioned at the same location and moved the entity picks up the water collision again (the water anims btw) and stays hidden. I just wish there was a collision response of 'no response' but could be monitored.


D4NM4N(Posted 2005) [#8]
i could be wrong here but i thike resetentity is ignoring all collisions SINCE the last updateworld to the statement
ie. this wont work

updateworld
.
.(goes round loop)
.
if entitycollided set latch to 1 (inside collision count loop)

if latch on
resetentity(blah)
positionentity @collision coords
reset latch
endif
moveentity .......


--------------------------------------------------
but this will (with a slight hang up on one frame)


updateworld
.
.(round loop)
.
if entitycollided set latch to 1

moveentity .......

if latch on
resetentity(blah)
positionentity @collision coords
reset latch
endif



it (seems) to reset for any movement before the resetentity and after the last updateworld. Can anyone else confirm this?? and also tell me how to post proper formatted code!!


DJWoodgate(Posted 2005) [#9]
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)



D4NM4N(Posted 2005) [#10]
thanks 4 your input, mabe its one for mr sibly himself :)


jfk EO-11110(Posted 2005) [#11]
the method I described practically IS a no response collision detection. Because if you store the coords prior Updateworld(), you'll get the coords of a non-collision set up. If you position the bullet after the updateworld at the coords again, but still hidden (collision off and reset), it may be possible to detect the collision and override any auto-reaction.

HideEntity will not only turn off collision during the hidden state, but also erase the meshes Collision event buffer, even without to call Udateworld(). At least when I tried it the last time, that was with V 1.88 if I remember right.


D4NM4N(Posted 2005) [#12]
damn.. you got me playing with it again ;)


DJWoodgate(Posted 2005) [#13]
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 []



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.




D4NM4N(Posted 2005) [#14]
Thanx for your help, i think ive worked it out now. in the future i will probably opt for shadowing.
this is how it looks at the moment (xcuse the untidy code =)

	For b.bullet=Each bullet
			
		b\phase=b\phase+1: 
		If EntityCollided (b\h,c_level) Or EntityCollided (b\h,c_water) Or EntityCollided (b\h,c_PLAYER) Or EntityCollided (b\h,c_SHIP)
			
			For cc=1 To CountCollisions(b\h)
				entityhit=CollisionEntity( b\h,cc )			
				ct=GetEntityType( entityhit)
				.
				.
				.
				.
				. (other Collisions are in here)
				.
				.
				.
				.
				
				If ct=c_WATER
					If b\waterlatch=0
						x#=CollisionX(b\h,cc)
						y#=CollisionY(b\h,cc)
						z#=CollisionZ(b\h,cc)
						nx#=CollisionNX(b\h,cc)
						ny#=CollisionNY(b\h,cc)
						nz#=CollisionNZ(b\h,cc)
						createripple(-6,x,y,z,16,12.5,nx,ny,nz,4,1)
						b\waterlatch=1
						
						b\collisionreset=1
					EndIf
					
				EndIf 
			Next
		EndIf
		
		If b\phase>1 If b\noexplo=0 MoveEntity b\h,0,0,b\speed
		
		If b\collisionreset=1  
			PositionEntity b\h,x,y,z   :
			ResetEntity b\h   :
			b\collisionreset=0
		EndIf
		
		If b\noexplo>0 EntityAlpha b\h,Float(1-(b\phase*.02)) 
		If b\phase=>50 Then 
			FreeEntity  b\h
			Delete b
		EndIf
		
	Next