Trigger and Collider scripts not working to set position

Hello all,
I am trying to make an entity go to a certain position after it hits a collision.
I would greatly appreciate any help :smiley:

What is the problem exactly? Can you share more information about the setup and script?

I have a cube going on the x-axis toward another box, I am trying to make a script so that when the cube hits the box it will go to a certain position using this.entity.setLocalPosition(0,0,0)

Probably you need to use this.entity.setPosition(0, 0, 0);

Ok, but do you know how to get the collision to work?

Below the manual page about collision.

Oh, I just noticed something on the tutorial! Thanks for sharing that link! I think I am good

I used code from the manual and it still doesn’t work, I used the Trigger code:

var Trigger = pc.createScript('trigger');

// initialize code called once per entity
Trigger.prototype.initialize = function() {
    this.entity.collision.on('triggerenter', this.onTriggerEnter, this);

Trigger.prototype.onTriggerEnter = function(entity) {
    entity.rigidbody.linearVelocity = pc.Vec3.ZERO;
    entity.rigidbody.angularVelocity = pc.Vec3.ZERO;
    // Reset back to roughly the position the entity started in.
    var position = entity.getPosition();
    this.entity.setPosition(-584.032, 10, 0);

This script works only if the entity with the script has no rigidbody component. Otherwise it’s not a trigger.

Also be aware that if an entity has a dynamic rigidbody, you can’t use setPosition(). You need to use rigidbody.teleport() instead.

Okay I will try what you sugested

Does the collision script need to have a collision component?