Collision Detection Problem


i'm making simple platform game actionscript 3. i've got player movements (walking, jumping) setup , working. tried add blocks player walk on, not through. kind of works. when player jumps while standing on block, jump, when lands bounces little bit, stays still on block (and able moved). can me revise code doesn't happen?

 

i've got 3 classes, player class, main class, , block class. i'm pretty sure problem in player class.

 

player class:

 package  {   import flash.display.movieclip;   import flash.events.keyboardevent;   import flash.display.stage;   import flash.ui.keyboard;   import flash.geom.point;    public class player extends movieclip{        private var gravity:int = 0;         private var speed:uint = 10;         private var bottomtrigger:point = new point(45 - 45, 105 - 60);        private var lefttrigger:point = new point(20 - 45, 60 - 60);        private var toptrigger:point = new point(45 - 45, 9 - 60);        private var righttrigger:point = new point(70 - 45, 60 - 60);          public function player() {             gotoandstop('still');              x = 100;             y = 0;         }         public function keydown(event:keyboardevent){             var keycode:uint = event.keycode                if(keycode == 37 || keycode == 65){ gotoandstop('walking'); scalex = -1; x-=speed; }             if(keycode == 39 || keycode == 68){ gotoandstop('walking'); scalex = 1; x+=speed; }              if(keycode == 40 || keycode == 83){ gotoandstop('crouch'); scalex = -1; }              if(keycode == 87 || keycode == 38 || keycode == 32){                  gravity = -15;                  y--;             }         }         public function keyup(){             gotoandstop('still')        }          public function checkcollision(){             for(var i:uint; i<main.blockarray.length; i++){                  if(main.blockarray[i].hittestpoint(bottomtrigger.x + x, bottomtrigger.y + y, true)){                       gravity = 0;                       y--;                  }                   if(main.blockarray[i].hittestpoint(lefttrigger.x + x, lefttrigger.y + y, true)){                       x++;                  }                   if(main.blockarray[i].hittestpoint(toptrigger.x + x, toptrigger.y + y, true)){                       y++;                  }                   if(main.blockarray[i].hittestpoint(righttrigger.x + x, righttrigger.y + y, true)){                       x--;                  }             }        }         public function applygravity(){             if(!onground()){                  gravity+=1;             }else{                  gravity = 0;             }              y+=gravity;        }          private function onground():boolean{             for(var i:uint; i<main.blockarray.length; i++){                  if(main.blockarray[i].hittestpoint(bottomtrigger.x + x, bottomtrigger.y + y - 1, true)){                       y = main.blockarray[i].y - main.blockarray[i].height/2 - height;                         return true;                  }             }         return false;   }   } } 

 

there 3 more lines closing out }. website code glitchy me. easier read here: hastebin

 

please note, when tested no errors came up. it's not there's error, it's it's not coming out how want it.



More discussions in ActionScript 3


adobe

Comments

Popular posts from this blog

after effects warning: unable to create drawing surface

Maximum number of authorizations reached!