Can someone explain Collision?

Blitz3D Forums/Blitz3D Beginners Area/Can someone explain Collision?

Black Hydra(Posted 2004) [#1]
Sorry but my collision code isn't working, and because I haven't done anything using true UpdateWorld collision yet I was wondering if someone could explain it to me.

Here is what I think I know already. Please correct me if I am wrong.

1) Entities have collision types stored on them to indicate what classification of collision they fall under.

2) Collision responses are set up with the Collisions command. In it I specify my collision type variables for the two objects I want to act upon and what method/response to use.

3) Collision properties are assigned via EntityRadius and EntityBox commands.

4) The Update world enacts on all of my choices and will move objects accordingly.

5) If I use Position commands rather than transpose/move commands for controlling entities I will need to run through all of my objects positional variables and adjust them after Update world like:
...
Enemy\X# = EntityX#(Enemy\ObjectNum)
...

But my code doesn't work. So if I am missing a key step or my understanding is faulty please tell me what I need to do.

Here is my code:



WolRon(Posted 2004) [#2]
But my code doesn't work.
Yeah, but WHAT doesn't work? player to box, bullet to player, bullet to box?

1-4 are correct. What you are talking about on statement 5, I have no idea.

By the way, use a [codebox]


Black Hydra(Posted 2004) [#3]
Nothing works. The player simply glides through everything.

What I meant by number 5 is that I use variables to track my objects positions and use Position Entity commands. This means that if the Update World command would move the entity as a result of a collision I would also need to manually readjust the variables aswell.


DJWoodgate(Posted 2004) [#4]
Entitybox coords are local to the object. ie, -1,-1,-1,2,2,2 would form a 2x2x2 box around an object centred on its origin. So your boxes for your cubes are way off.

So collision boxes will conform to your entities translation and rotation, but they are not effected by entity scale. So if you scale your entity up you will need to make the box bigger. Oh, and they do not work very well with sprites and last time I tried it they were not too hot interfacing with proper elipsoids either, but as you have only set a spherical radius for the other collision type that should be ok.

The docs do not explain any of this very well. (if at all).

Oh and just FYI only elipsiod to elipsiod collisions work when both entities are moving - last time I tried it anyway. (If this has changed it has not been documented either). In short you can never be sure of anything so the best thing to do is suck it and see.

As to 5, Yes, though you might consider moving using translateentity and referencing an entities position using EntityX() etc. Up to you though, whichever you feel is easier.


Jeremy Alessi(Posted 2004) [#5]
You have to think about Blitz collisions as the moving object is the ellipsoid ... only non-moving entities can successfully use Box or Poly collision. So if you set EntityBox for an object ... it is only for other objects to collide with it ... not for it to collide with other objects. You can get a lot out of the collisions when you think about it like this.


Black Hydra(Posted 2004) [#6]
Okay I understand that whole -1, -1, -1, 1, 1, 1 thing now. You see, in the help document it lists the things as Positions and Dimensions not coordinates for the rectangular solid.

I wasn't intending on doing any collisions with moving polygons or boxes but that is good to know. I guess I might have to buy NGC if I want to do anything more complicated that this.

So your saying what I need to do is fix my box coordinates? So assuming I haven't made any goofy mistakes with my code that should fix it?

As for the translate entity as opposed to position entity, this is only a prototype so when I actually do my game I will probably use your method, however, as for now I am more interested in finishing this as a gameplay testing tool than as an actual proffessionally coded game.

I feel like such a noob now after navigating here from DBPro... Ah well, it was definitely worth it.


DJWoodgate(Posted 2004) [#7]

So your saying what I need to do is fix my box coordinates? So assuming I haven't made any goofy mistakes with my code that should fix it?



Should do, although it could be I have missed something else. I have not done any collision stuff for a while.


Okay I understand that whole -1, -1, -1, 1, 1, 1 thing now. You see, in the help document it lists the things as Positions and Dimensions not coordinates for the rectangular solid.



Just remember the last three parameters of the entitybox command define the extent of the box on each axis, not the end coordinates, so -1,-1,-1,1,1,1 is not what you want here, it is -1,-1,-1,2,2,2.

BTW you do not actually need to define a box at all for those cubes. Why? I think blitz defines a default box of -1,-1,-1,2,2,2 and a default radius of 2 for each entity. It is probably good practice to define them anyway though as that behaviour may change.


Black Hydra(Posted 2004) [#8]
Okay, I've switched to using radius's as I've imported a new enemy model I made.

However, now I am having another problem. It doesn't seem to matter what size I set the radius with it always acts the same size.

Here is the code:

 For Counter = 1 To 20
  Num = LoadAnimMesh("MediaS/Glagar.x")
  TextureNum = LoadBrush("MediaS/Glagar.bmp")
  PaintEntity Num, TextureNum
  ScaleEntity Num, 5.0, 5.0, 5.0
  X# = Rnd(-150, 150)
  Y# = Rnd(-150, 150)
  Z# = Rnd(-150, 150)
  PositionEntity Num, X#, Y#, Z#
  EntityRadius Num, 5.0
  EntityType Num, TYPE_BOX
 Next 


I know it is slightly erroneous of me to be using the TYPE_BOX even though it isn't a box and I'm using spherical collision, but that isn't the problem.

While I am at it (and to prevent creating a new thread):

I am using Milkshape3D to make the object and when I exported it the animation instead of stretching the object where the faces are the faces simply pull apart. It doesn't look like this in Milkshape which means I assume either I exported it incorrectly or the loading of animation files works differently than expected. Any ideas.

Thanks for all your help guys.


WolRon(Posted 2004) [#9]
Can't tell by the code you've posted, but (just in case you're confused) ScaleEntity 5.0 and EntityRadius 5.0 are not the same thing.

For instance, if your mesh is originally 2 units high, scaling it 5 times will make it 10 units high, which would be 5 units higher than the collision sphere.

Aside from that, your code looks OK. It must be how you are using it???