I want my main player to touch a box when it hits it, but not against it, so it touches but passes through it. How should I set
Hi @Ozden_Delibas,
I think you need a trigger? Check this tutorial if that’s what you are looking for:
https://developer.playcanvas.com/en/tutorials/collision-and-triggers/
Your trigger doesn’t work as a trigger as long as it has a rigidbody component. So remove the rigidbody component from the trigger entity. Also make sure your player has a rigidbody component and a collision component. On your screenshot I only see a collider script, I’m not sure what you do with that.
Hello, I’ve looked at the article posted above, but my “Player” object is not able to fit inside a particular tag. Below are the methods I tried, what am I doing wrong?
what i tried
Controller.prototype.initialize = function() {
this.entity.collision.on('triggerenter', this.onTriggerEnter, this);
};
Controller.prototype.onTriggerEnter = function(entity) {
if(entity && other.tags.has('saymaa')){
console.log('true');
}
};
Controller.prototype.initialize = function() {
this.entity.collision.on('triggerenter', this.onTriggerEnter, this);
};
Controller.prototype.onTriggerEnter = function(other) {
if(other.tags.has('saymaa')){
console.log('true');
}
};
Controller.prototype.initialize = function() {
this.entity.collision.on('triggerenter', this.onTriggerEnter, this);
};
Controller.prototype.onTriggerEnter = function(result) {
if(result.tags.has('saymaa')){
console.log('true');
}
};
Controller.prototype.initialize = function() {
this.entity.collision.on('triggerenter', this.onTriggerEnter, this);
};
Controller.prototype.onTriggerEnter = function(result) {
if(result.other.tags.has('saymaa')){
console.log('true');
}
};
As a result, it doesn’t say “true” on the console screen. What is the reason why the object is not triggering?
Note: Controller script is bound to “Player” object
The problem is that the script is on the player entity. Because of that you should change your initialize code to something like below.
this.app.root.findByName("TriggerEntity").collision.on('triggerenter', this.onTriggerEnter, this);
To be honest, that won’t work either, because then the other code will no longer be correct. The bottom line is that you are now using the player as a trigger which is not a trigger, so you have to take a look at this.
Thank you, I will try and report the result here.
It worked temporarily. Thank you. If I find a better method, I’ll add it here. I wish you a good day.
What do you mean with this? How does your code look like at the moment?
Controller.prototype.initialize = function() {
this.app.root.findByName("Destroy").collision.on('triggerenter', this.onTriggerEnter, this);
};
Controller.prototype.onTriggerEnter = function() {
this.count++;
this.countText.element.text= +this.count;
this.speed += 0.7;
var s = this.app.root.findByName('newTilee');
setTimeout(() => {
s.destroy();
},150);
};
The code structure is like this, I can’t do the action according to the tag in the trigger. Therefore, in the future, situations may be mixed in another triggering process.
That’s right. Therefore you need to add the script to the trigger entity and then you be able to check if the collision entity is the player entity. The downside is that the code inside the function becomes a little more complex.
Thanks again for your help. I’m learning slowly.
Hello just forked your project and played around with it.
Do you mean something like this?
Sorry for bad quality
Hi, no, what I want to do is add an object to the front of each track without a rigidbody, and when I pass the ball through that object, it will destroy the remaining track and increase the count value by 1.