class ballBehavior extends Sup.Behavior{ private ballActor: Sup.Actor; private ballAngle: number; private ballPosition: Sup.Math.Vector3; private ballVelocity: number; constructor(ball) { super(ball); this.ballActor = new Sup.Actor("Ball"); this.ballActor.setPosition(0, 0, 0); this.ballAngle = 0; this.ballPosition = new Sup.Math.Vector3; this.ballVelocity = 0; this.ballActor.addBehavior(ballBehavior); } update(){ this.ballAngle += this.ballVelocity; //Constrains the angle between 0 and 2pi if(this.ballAngle > Math.PI * 2) this.ballAngle = 0 + this.ballAngle - Math.PI * 2; }else if (this.ballAngle < 0) this.ballAngle = Math.PI - this.ballAngle + Math.PI * 2; //Maybe a little spinback on the pointer? this.ballPosition = new Sup.Math.Vector3(Math.cos(this.ballAngle) * wheelActor.getLocalScaleX() * 100 / 100, Math.sin(this.ballAngle) * wheelActor.getLocalScaleX() * 100 / 100, 0); if(Sup.Input.wasKeyJustPressed("LEFT")) this.ballVelocity = 0.5; } }
dont declare all variables into constructor, always on top of this