I decided to test the standard physics and collision in the engine. I used an example:
start () {
this.rigidbody = this.node.getComponent(RigidBody2D);
this.collider = this.node.getComponent(BoxCollider2D);
if( this.collider ) {
this.collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
}
}
onBeginContact( selfCollider: BoxCollider2D, otherCollider: BoxCollider2D, contact: IPhysics2DContact | null ) {
if( otherCollider.name == "star<BoxCollider2D>" ){
otherCollider.node.getComponent("Star").destroyStar();
this.score++;
this.scoreLabel.string = "Score: " + this.score;
}
}
Here’s my code:
start() {
this.rigidbody = this.node.getComponent(RigidBody2D);
this.collider = this.node.getComponent(Collider2D);
if (this.collider) {
this.collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, true);
}
this.node.getComponent(Animation).play("idle");
}
onBeginContact(selfCollider: BoxCollider2D, otherCollider: BoxCollider2D, contact: IPhysics2DContact | null) {
if (otherCollider.name == "Floor<BoxCollider2D>") {
this.jumpHeight = 0;
}
}
My code gives this error:
can't assign to property "jumpHeight" on true: not an objecterrorInfo.stack ?
How can I correct this error?