Getting control of collisions in code.

Blitz3D Forums/Blitz3D Beginners Area/Getting control of collisions in code.

gerald(Posted 2012) [#1]
Hi,

I can only access a collision with the countcollisions/crash example in the book. This means all collisions with the player/camera are the same and this is the only collision I can access in code.

The code: Collisionentity() and Entitycollided(entity,type) do not have examples in the help reference or book text. I would like to get access to specific collisions ie an individual entity (health bonus) and a specific entity target or soldier and not a scenery or terrain collision.

What parameters go in the parenthesis after the collision entity and entitycollided calls? What value is returned, the name of the entity (tank1) or the type (gallery) or a true/false value?

I would appreciate the exact code usage. I have tried several simple guesses but no luck.

I want to do stuff like decrease health for hitting a tree or rock and increase it for hitting a health bonus entity. I need to seperate my collisions from the general count collisions/crash= code.


Thanks, Gerald


Yasha(Posted 2012) [#2]
EntityCollided returns the first entity of a specified collision type that collided with the passed entity on the last collision update.

So if you have a player, and a bunch of objects to which you have assigned the collision type ROCK, you could do EntityCollided(player, ROCK) to get the specific rock they hit.

CollisionEntity requires you to use CountCollisions. CountCollisions returns the number of collisions the entity was in last update, and you can iterate over the list of collisions with CollisionEntity to test which was the second object involved. This is probably closer to what you want to do.

For things like powerups it might be more sensible to ditch collisions altogether and just do it based on distance (against a set powerup radius). There's no clean way to have a no-result collision in B3D's builtin collision engine, so assuming you want the player not to be obstructed by pickups, using collisions would be unnecessarily complicated.


gerald(Posted 2012) [#3]
I finally got entitycollided(camera,5) to work. The expression is "true" if the camera collides with entity type 5 as written and will control an if then statement as is. Doesn't even have to be set equal to true. My health item type_health=5 works. The value in a text statement is unusual. It returned 6357628 as the value when written to see if it worked. Then it worked as true in an if then.




How do you find where the camera is (x,Y). In 2D the command mousex and mousey are easy and tell you exactly where your mouse is. Where is the camera/player? Camerax, cameraY..? I would like to draw an enemy near the camera location to interact with.


Floyd(Posted 2012) [#4]
The camera is an entity, which is why EntityCollided works with it. So you use EntityX() etc.