Collision calls returning no value?

Blitz3D Forums/Blitz3D Programming/Collision calls returning no value?

John Blackledge(Posted 2009) [#1]
A new engine, and I'm up to the point where I want to implement falling/gravity.
So of course I'll need to know when I hit the floor to reset the gravity variable.

The player has an EntityType.
The terrain has an EntityType.
All collisions for all types have been set.
The player is happily walking up and down slopes, using a constant TranslateEntity piv,0,-World\wgrav#,0 type call.

But I am getting zero return value from both EntityCollided(piv,TYPE_TERRAIN), and CountCollisions(piv).

As usual, I'm hoping someone says, "But have you thought of...." and I slap my hand to my forehead. But it's been 10 hours now, and I'm climbing the walls. Thanks, people.


John Blackledge(Posted 2009) [#2]
Found it!

I needed an extra UpdateWorld() between TranslateEntity() and EntityCollided() or CountCollisions() so that those calls returned values.
Duh?


_Skully(Posted 2009) [#3]
Just move the code so that...

Changes to entity positions happen
UpdateWorld
Tests for collisions happen
RenderWorld
flip

or
Tests for collisions happen
Changes to entity positions happen
UpdateWorld
RenderWorld
Flip


MadJack(Posted 2009) [#4]
Yes - probably not a good idea to have multiple updateworlds floating around. Screws up animation timing for a start.


John Blackledge(Posted 2009) [#5]
Thanks, guys.
It seems so obvious once you realise.
But it still took 10 hours!
Doh!


jfk EO-11110(Posted 2009) [#6]
Additional UpdateWorlds are costy, cpu-wise. But when you need one, use UpdateWorld(0), as far as I know this will leave the animations untouched.


GIB3D(Posted 2009) [#7]
Is it ok to have 2 UpdateWorlds in the code? For me, I'm making a multiplayer game but I need one UpdateWorld in the UpdatePlayer function (which only updates your player) so I can animate the player based on his last movement and the other UpdateWorld in the main loop to update the other player's animation. Your player's UpdateWorld is inside two If..End statements. So it's not called if your player's model is not loaded yet and you are dead, that's why I have the second UpdateWorld in the main loop.


RifRaf(Posted 2009) [#8]
Gia,

probably better to find another way to handle your system , so that you can use one updateworld()


GIB3D(Posted 2009) [#9]
Oh ok, I'll do that then, I'm sure I can do it some other way.


jfk EO-11110(Posted 2009) [#10]
I would also suggest to use only one UpdateWorld directly in your mainloop. But it might be ok to do an additional UpdateWorld in a special Situation.