Can a Collider differentiate between two objects?

Options

Hi! I have not found much information about collisions in Lens Studio.

But I don't know if it is possible to differentiate whenever Object A or Object B collides with my main collider. In Unity I would use tags but I haven't found a way in Lens.

This is the script just in case it helps:

// -----JS CODE-----
//@input Component.Text currentScoreNumber
//@input Component.Text finalScoreNumber
//@input Component.Text3D finalScoreNumber3D

var currentScore = 0;
var sceneObjj = script.getSceneObject();
var rb = sceneObjj.getComponent("Physics.ColliderComponent");

//Collisions
rb.onCollisionEnter.add(function (e) {
var collision = e.collision;
currentScore ++;
script.currentScoreNumber.text = currentScore.toString();
script.finalScoreNumber.text = currentScore.toString();
script.finalScoreNumber3D.text = currentScore.toString();
script.getSceneObject().getComponent("Component.AudioComponent").play(1);
print("CollisionEnter(" + collision.id + "): ---> " + collision.collider);

print(currentScore);

});

Thanks in advance!

Answers

  • Kevando
    Kevando Posts: 76 🔥🔥
    Options

    Yeah colliders should have a tag or something. I bet collider.name gives you the object name or something like collider.getSceneObject().name should work. bottom line is yes, you can do this.