How can I replace the “collision” property of an object, the “sphere” attribute of type “radius” with code?
For example, we can set the size of the object with the code
this.entity.setLocalScale(1.5,1.5,1.5);
,
how do I do this for collision?
How can I replace the “collision” property of an object, the “sphere” attribute of type “radius” with code?
For example, we can set the size of the object with the code
this.entity.setLocalScale(1.5,1.5,1.5);
,
how do I do this for collision?
Hi @Onur_Ozturk! That should be something like below.
this.entity.collision.radius = 1;
Hi, thank you it works. However, when I update the radius size, the speed of the object instantly becomes 0. How can I prevent this?
Most likely because changing the radius recreates the physics body. You could copy the linear and angular velocity of the body before making the change, and reapply it afterwards.
https://developer.playcanvas.com/api/pc.RigidBodyComponent.html#linearVelocity
https://developer.playcanvas.com/api/pc.RigidBodyComponent.html#angularVelocity
Controller.prototype.update = function (dt) {
//}
var moveVect = new pc.Vec3(moveVert, 0, moveHoriz);
rb.applyForce(moveVect.scale(this.speed));
var direction_moveVect = new pc.Vec3(direction_moveVert, 0, direction_moveHoriz);
direction_rb.applyForce(direction_moveVect.scale(this.direction_speed));
};
Hello, thank you for your reply. However, I am constantly applying a force inside the “update” function.
Is there a way to change the radius without rebuilding the physics body?
No I don’t think so.
But changing the radius won’t affect your update method I think. It will execute at that exact point. Try it.
Let me explain why I want this kind of thing. When the top left bar is full, I activate random features. When the sphere gets bigger and I update the collision area, the ball stops momentarily, then even if it continues to regain speed, the probability of falling down the tracks is very high because its speed is slow. How can we apply a solution to this?
I can’t test it right now, but what I imagined is this:
const linear = entity.rigidbody.linearVelocity.clone();
const angular = entity.rigidbody.angularVelocity.clone();
this.entity.collision.radius = 1;
entity.rigidbody.linearVelocity = linear;
entity.rigidbody.angularVelocity = angular;
It worked oddly enough. My logic has failed here. Thank you.