How to detect which object was collided by the main object?

As far as I know, I must have some objects with rigid body’s and collisions but, can someone help me in this?

I’ve “n” objects with animations (actually 6 objects) and I want to detect each collision, but I added the collision script to my main object (which I’m controlling).

I tried this in my main object:

var Colliders = pc.createScript('colliders');

// initialize code called once per entity
Colliders.prototype.initialize = function() {
   // Each of this objects has a collision and rigid body 
    this.entity.collision.on('collisionstart', this.onCollision, this);
    this.model1 ='Man');
    this.model2 ='Man02');
    this.model3 ='Man03');
    this.model4 ='Man04');
    this.model5 ='Man05');
    this.model6 ='Man06');

Colliders.prototype.onCollision = function (result) {

But at the moment that my main object collided with any object, the console log is not printed and if I add this collision script to each object instead of in my main object, the console log is printed. Sorry for my misspelling.

Hi @Axel_Saucedo,

Take a look at Collision and Triggers tutorial on how to start detecting collisions between your objects.

It explains the difference between triggers and rigid bodies, for detecting collisions and provides starting code.

Your collision script seems correct, to be attached to your main object, most likely the issue is somewhere on your scene setup.

If you are unable to resolve this, try posting a working scene example to take a look.

1 Like

What kind of animations are these? The rigidbodies/collision volumes won’t move with the animation.

They are static for now due to I haven’t complete the entire animation yet, they’re walking but in the same coordinates
this may turn out to be useful, it’s a script that i use on arrow

1 Like