Collision problem:SOLVED

im trying to target a specific entity. i need help.

initialize: function () {
            this.entity.collision.on('contact',this.contact,this);
            
        },
        contact: function(result){
            var x = app.root.findByName('player');
            if(result.x.rigidbody){
                
                x.entity.rigidbody.teleport(17,6,0);
            }
        }
Collider.prototype.initialize = function () {
    this.entity.collision.on('collisionstart', this.onCollisionStart, this);
    
//name of 1st object
        this.Entity1 = this.app.root.findByName('entity1');

//name of 2nd object
        this.Entity2 = this.app.root.findByName('entity2');
};

Collider.prototype.onCollisionStart = function (result) {
    
    //Check to see if Entity1 has hit this object
    if (result.other == this.Entity1) {
        
        alert("you hit me!!");
    }

};

See if this helps :point_up_2:t5:

it says on line 11 that colider was not defined

Are you copying and pasting this code? Then your script should be called collider.js.

it detects the colition, but it doesn’t run the if statement

Send me your project link and give me access

https://playcanvas.com/editor/project/581321

Does the entity you’ve attached the script to have a rigid body and a collision component, and does it take part in the collision or do it’s children have the rigid body and the collision component and take part in the collision?

yes, the player entity has a rigidbody and so does the other entity

What exactly is the error message?

the colition is detected, but the if statement is not being ran. there was no error message\

Can you put a debugging print statement before, in and after the if statement? Tell me the result

it probaly isn’t working because i was using legacy scripting

That’s pretty likely. Does it work now?

yes it does now work