Hi,
How can I test wether the ball is inside or outside a sensor that I have? The code that I’m using is very unreliable due to me checking in the Update function and hence being dependant on frame rates.
As you can see the balls building box is extended (being swept) between frames and the ball still thinks it’s on the sand even when it has come to a halt. (Maybe it’s a little hard to see but there is a purple debugging box connecting the ball to the sand.)
The code I’m currently using keeps saying isTouching is true when the ball is outside the sand.
Update() {
if (this.rb._b2Body.m_contactList && this.rb._b2Body.m_contactList.other.m_userData) {
// let isTouchingCollider = this.rb._b2Body.GetContactList().other.m_fixtureList.TestPoint(this.rb._b2Body.GetWorldPoint(this.rb._b2Body.GetLocalCenter()));
let isTouchingCollider = this.rb._b2Body.GetContactList().contact.IsTouching();
if (!isTouchingCollider) {
return;
}
if (userData.type == ColliderType.MGEntityTypeSand) {
if (this.cl.body.linearVelocity.x != 0 && this.cl.body.linearVelocity.y != 0) {
var point = new cc.Vec2(0, 0);
var oppositeForceMultiplier = -30;
let oppositeForce = new cc.Vec2(this.cl.body.linearVelocity.x / this.sandFriction * oppositeForceMultiplier, this.cl.body.linearVelocity.y / this.sandFriction * oppositeForceMultiplier);
this.rb.applyForce(oppositeForce, point, true);
}
}
}
}
If Cocos Creator doesn’t have a FixedUpdate method then how would I check, independently of frame rate, where the ball currently is?
Many thanks in advance!