1 decade ago by codesavage
First off, apologies if the question I ask is silly or vague. This is my first post on the board, and I'm having some trouble wrapping my head around how some things work.
I'm currently working on a top/down shooting game (think Geometry Wars). I'm changing the animation angle of my player ship to make it face the direction that the player presses. That works in a very crude way, but what I'd like to do is have the ship rotate from its current position to the new one. So if the ship is traveling upwards and the player presses left, the ship would visually rotate 90 degrees to the left (rather than instantaneously just start facing left). I'd also like to have the animation work diagonally as well, but that might be a separate issue. Here's my current player update function:
As you can see, I tested out some code for rotating the ship manually, but I'm not sure how to use that to make it happen automatically based on the direction the ship is moving. Any help would be appreciated!
I'm currently working on a top/down shooting game (think Geometry Wars). I'm changing the animation angle of my player ship to make it face the direction that the player presses. That works in a very crude way, but what I'd like to do is have the ship rotate from its current position to the new one. So if the ship is traveling upwards and the player presses left, the ship would visually rotate 90 degrees to the left (rather than instantaneously just start facing left). I'd also like to have the animation work diagonally as well, but that might be a separate issue. Here's my current player update function:
update: function() { var accel = this.accelSpeed; if( ig.input.state('left') ) { this.accel.x = -accel; //this.currentAnim.angle -= Math.PI/.7 * ig.system.tick; this.currentAnim.angle = 4.71238898; } else if( ig.input.state('right') ) { this.accel.x = accel; //this.currentAnim.angle += Math.PI/.7 * ig.system.tick; this.currentAnim.angle = 1.57079633; } else { this.accel.x = 0; } if( ig.input.state('up') ) { this.accel.y = -accel; this.currentAnim.angle = 0; } else if( ig.input.state('down') ) { this.accel.y = accel; this.currentAnim.angle = 3.14159265; } else { this.accel.y = 0; } if( ig.input.state('shoot') ) { ig.game.spawnEntity( EntityStandardBullet, this.pos.x, this.pos.y, {flip:this.flip} ); } this.parent(); }
As you can see, I tested out some code for rotating the ship manually, but I'm not sure how to use that to make it happen automatically based on the direction the ship is moving. Any help would be appreciated!