1 decade ago by kanito
Hi everyone!
I have a strange problem with one entity. The intention of the script is to rotate the entity and face it to one point defined by the mouse when the user clicks on the screen.
The entity rotates, but it doesn't stop when it reaches the angle.
This is the code:
Can anyone help me?
Thanks in advance!
I have a strange problem with one entity. The intention of the script is to rotate the entity and face it to one point defined by the mouse when the user clicks on the screen.
The entity rotates, but it doesn't stop when it reaches the angle.
This is the code:
EntityPlayer = ig.Entity.extend({ size: {x: 66, y: 31}, animSheet: new ig.AnimationSheet( 'media/T72.png', 66, 31 ), init: function( x, y, settings ) { this.parent( x, y, settings ); x = 0; y = 0; angle = 0; clicked = false; this.addAnim( 'idle', 1, [0] ); }, update: function( ) { if( ig.input.pressed( 'click' ) && clicked == false ){ clicked = true; x = this.pos.x; y = this.pos.y; mx = ig.input.mouse.x; my = ig.input.mouse.y; angle = Math.acos((x-mx)/(Math.sqrt((x-mx)*(x-mx) + (y-my)*(y-my)))); } if( (Math.abs(this.currentAnim.angle) < (Math.abs(angle + 0.1))) && (Math.abs(this.currentAnim.angle > (Math.abs(angle - 0.1)))) && (clicked == true)){ this.anims.idle.angle = angle; clicked = false; } else if ( clicked == true ){ this.anims.idle.angle = this.currentAnim.angle - 0.01; document.writeln(' # object: ', Math.abs(this.currentAnim.angle), ', angle: ', Math.abs(angle), ', clicked: ', clicked); } else { clicked = false; } } });
Can anyone help me?
Thanks in advance!