javascript - Player facing away from the wall should not collide -
i'm working on first javascript game. top down 2d view (think gta 1/2). i'm having trouble collision detection. have multiple entities 1 player , other static object (let's wall simplicity).
each object has x/y coordinates , player has velocity , angle (which way player facing 0-360 degrees). collision detection against wall works fine , stop velocity on 1 of axis if player collide having result player can "slide" agains wall.
now issue: once player collides agains wall movement on 1 of axis stopped. if player after turns around , facing away wall movement of axis still stopped since ha collided.
i player, if facing away object, free move how want's how achieve this? guess need figure out way player facing , if facing against or away object?
for( var = 0; < game.entities.length; i++ ) { if( this._collision( game.entities[i] ) ) { var distancex = game.entities[i].x - this.x; var distancey = game.entities[i].y - this.y; if( distancex < 0 ) distancex *= -1; if( distancey < 0 ) distancey *= -1; if( !stopx ) { stopx = ( distancex > distancey ); } if( !stopy ) { stopy = ( distancex < distancey ); } } }
i figured out how this:
var degrees = ( math.atan2( game.entities[i].x - this.x, game.entities[i].y - this.y ) * 180 / math.pi ) + this.angle
Comments
Post a Comment