Issue when i set position of other entity then position is not change

-----------CODE--------------

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


Trigger.attributes.add('Newobject',{type:'entity'});
Trigger.attributes.add('Game2',{type:'entity'});
// initialize code called once per entity
Trigger.prototype.initialize = function() {
     this.entity.collision.on('triggerenter', this.onTriggerEnter, this);
};


Trigger.prototype.onTriggerEnter=function(event)
{
  console.log(event.name);   
  var p=this.Newobject.getPosition();  
console.log(p);
  this.Game2.setPosition(p.x,p.y,p.z);    
  
    // this.Game2.enabled=true;  
  //  this.Game2.setPosition(p.x,p.y,p.z);  
  // // // console.log(event.Game2.position);  
  };

Hi @HasnainX,

Is your this.Game2 an entity with a dynamic rigidbody component? If that’s the case you can change it’s position only by using the teleport() method on that component. Since this object is fully controlled by physics:

this.Game2.rigidbody.teleport(p.x, p.y, p.z);
1 Like

No Game2 is other entity i want to add position of newobject in Game2 when my object collides then trigger function will be called.

Can you share your project url to take a look? Not sure what’s wrong here.

I want to add other patch when they collide the end box

Hi @HasnainX, any chance you share your editor url or at least screen grabs of you set up these entities?

1 Like

https://playcanvas.com/editor/scene/1030637

Right now, setPosition() on Game2 entity won’t work because, this entity has children with static rigidbody. You can move a rigidbody component by using teleport() method. So you need to go and teleport each child entity that has a rigidbody component.

One way you can achieve what you want more easily with a trick, is to have your second level aligned with the first, have it disabled on initialize and when the time comes (on collision) just enable it by using this.entity.enabled = true . While the entity is disabled it isn’t part of the physics simulation, so you can use the regular setPosition() method.

https://developer.playcanvas.com/en/api/pc.Entity.html#enabled

1 Like