Collision question

Blitz3D Forums/Blitz3D Programming/Collision question

John Blackledge(Posted 2010) [#1]
My engine is structured thus:

While
Tweening
UpdateWorld()
RenderWorld()
MyWorldUpdate() <- all movement and text to screen
Flip
Wend

Collisions are working fine, but in MyWorldUpdate() calls such as EntityCollided() only return zero.
I need to know what I've hit.
Is UpdateWorld() clearing collisions from the last loop?


Ross C(Posted 2010) [#2]
Only thing i can think of is the entity your providing for the EntityCollided(), is not actually an entity. Maybe it's lost it's reference in the function?


GfK(Posted 2010) [#3]
Are you using more than one UpdateWorld (i.e. is there one in myWorldUpdate())?


Kryzon(Posted 2010) [#4]
Not related to the problem, but I think you should structure it like so:

MyWorldUpdate() <- all movement --- (could also be AI, Input, Texture Animations, etc.)
UpdateWorld()
RenderWorld()
Render2D() ;Text and image stuff.
All "user" operations first, then let Blitz3D collision\animate everything, and then render the final result.


John Blackledge(Posted 2010) [#5]
The entity in question is the player pivot, and I've checked, all collison settings (EntityType etc) are good.
Collisions _are_ happening, it's just as if all collision reporting is being zeroed.

Maybe Kryzon has the answer, but of course what I wanted was to have text readouts within the code that was generating the collisions.

All other suggestions will be gratefully received.


Warner(Posted 2010) [#6]
Is UpdateWorld() clearing collisions from the last loop?
You must mean RenderWorld(), since UpdateWorld() is performing all collisions.
Maybe the problem is caused by the tweening. Ie the actual collision has occured a few frames back.


Zethrax(Posted 2010) [#7]
The purpose of UpdateWorld() is to handle all the deferred dynamics stuff, including collisions, and then reset it all ready for the next update. If you do your UpdateWorld() before you do your positioning, etc, then you're going to end up with some strange behavior.

The reason your collisions are still working there, is that they're actually being processed by UpdateWorld() for the previous loop iteration.


John Blackledge(Posted 2010) [#8]
Thanks for that.

It seems that MyWorldUpdate() has to be immediately before UpdateWorld().
So I have (based on Mark's Render Tweening):
Repeat
elapsed=MilliSecs()-time
Until elapsed
ticks=elapsed/period
tween#=Float(elapsed Mod period)/Float(period)
For k=1 To ticks
time=time+period
If k=ticks Then CaptureWorld
WorldUpdate()
UpdateWorld()
Next

It doesn't work if it's before the Repeat (?)


MoonShadow(Posted 2010) [#9]
I'm having the same problem, I think this is very basic, but I can't get this right. I just want to know if EntityCollided become TRUE at any point. :oS


MoonShadow(Posted 2010) [#10]
For example:

sphere=CreateSphere( 32 )
PositionEntity sphere,-2,0,5

cone=CreateCone( 32 )
EntityType cone,type_cone
PositionEntity cone,2,0,5

type_sphere=1
type_cone=2

sphere_radius#=1

EntityType sphere,type_sphere
EntityType cone,type_cone

Collisions type_sphere,type_cone,2,2
While Not KeyDown( 1 )

x#=0
y#=0
z#=0

If KeyDown( 203 )=True Then x#=-0.1
If KeyDown( 205 )=True Then x#=0.1
If KeyDown( 208 )=True Then y#=-0.1
If KeyDown( 200 )=True Then y#=0.1
If KeyDown( 44 )=True Then z#=-0.1
If KeyDown( 30 )=True Then z#=0.1

MoveEntity sphere,x#,y#,z#

If KeyDown( 26 )=True Then sphere_radius#=sphere_radius#-0.1
If KeyDown( 27 )=True Then sphere_radius#=sphere_radius#+0.1

EntityRadius sphere,sphere_radius#


; Perform collision checking
Collided=EntityCollided (sphere,type_cone2) ;???

UpdateWorld

RenderWorld

Text 0,0,"EntityCollided is: " + Collided  ;???

Flip
Wend
End 


Or maybe just saying:
Text 0,0, "Did Entity Collide? : " + EntityCollided (sphere,type_cone2)

To see if EntityCollided returns TRUE?


Ross C(Posted 2010) [#11]
Collided=EntityCollided (sphere,type_cone2)

I don't see an EntityType for "type_cone2", only "type_cone"


MoonShadow(Posted 2010) [#12]
I'm sorry, that was a typo (missed type)
It should say:

EntityCollided (sphere, type_cone)

but still it doesn't work :oS


_PJ_(Posted 2010) [#13]
@John Blackledge -
Yes, you need to call updateworld after everything's been done that affects the entities. Updateworld then can check all the collisioninfo etc.

@MoonShadow
This works fine here:

Graphics3D 1024,768,32,6
SetBuffer BackBuffer()

camera=CreateCamera()

sphere=CreateSphere( 32 )
PositionEntity sphere,-2,0,5

cone=CreateCone( 32 )
EntityType cone,type_cone
PositionEntity cone,2,0,5

type_sphere=1
type_cone=2

sphere_radius#=1

EntityType sphere,type_sphere
EntityType cone,type_cone

Collisions type_sphere,type_cone,2,2
While Not KeyDown( 1 )

x#=0
y#=0
z#=0

If KeyDown( 203 )=True Then x#=-0.1
If KeyDown( 205 )=True Then x#=0.1
If KeyDown( 208 )=True Then y#=-0.1
If KeyDown( 200 )=True Then y#=0.1
If KeyDown( 44 )=True Then z#=-0.1
If KeyDown( 30 )=True Then z#=0.1

MoveEntity sphere,x#,y#,z#

If KeyDown( 26 )=True Then sphere_radius#=sphere_radius#-0.1
If KeyDown( 27 )=True Then sphere_radius#=sphere_radius#+0.1

EntityRadius sphere,sphere_radius#


; Perform collision checking
Collided=EntityCollided (sphere,type_cone) ;???
UpdateWorld

RenderWorld

Text 0,0,"EntityCollided is: " +Str( Collided ) ;???

Flip
Wend
End 


It may be important just to mention that the collision result only applies to the instance of collision, after that, even if the entities remain 'touching', they are no longer actively 'colliding'. So in short, you will see the Entityhandle flicker up only once, then remain at 0 unless the sphere tries to "move through" the cone again.


MoonShadow(Posted 2010) [#14]
Malice Thanks! I don't know where I went wrong before, may be it was the typo idk, I was ready to make my own collision detection with distance formula. Well, thanks again Malice


jfk EO-11110(Posted 2010) [#15]
edit: uh, solved.