Ironrind Posted October 13, 2013 Report Share Posted October 13, 2013 I'm having trouble with actor objects floating through walls and ceilings. What I am trying to do is create a simple collision code for enemies/npcs that does not allow them to walk through walls or hop through ceilings. In the picture above, you can see the player sitting on the dark gray box while the other two npcs get sucked through the wall. They are attempting to follow the player, but constantly get snagged. Can I get some advise for correcting this? Wall collision event for npcs: vspeed=0; y-=abs(abs(hspeed)*0.2)+2; if (!ground) { //lower than wall if (y>other.y) { hspeed*=-1; ground=0; if (x<other.x) x-=5; else x+=5; } //above wall else { ground=1; } } Here is the gmk: http://www.mediafire.com/download/5xxgfksb9c0guk1/AngCollisionSystem04.gmk Edit: I'm a bit a closer using a method I found in an old thread on google. The walls and ceiling lock the player in, but the player is still sticking and rising to walls. Collision event: //stay above ground if (ground) { vspeed=0; y-=abs(abs(hspeed)*0.2)+2; } //set ground if (!ground) {ground=1; hspeed=0;} //hit wall and ceiling { var dist,dir,xxdir,yydir; dist=point_distance(x,y,xprevious,yprevious); dir=degtorad(point_direction(xprevious,yprevious,x,y)); xxdir=cos(dir); yydir=-sin(dir); x=xprevious; y=yprevious; repeat dist{ if place_meeting(x+xxdir,y,other.object_index) hspeed=0; else x+=xxdir; if place_meeting(x,y+yydir,other.object_index) vspeed=0; else y+=yydir; } } gmk: http://www.mediafire.com/?g3eeh63y5be1lz8 Edit: Nevermind. Figured it out. Link to comment Share on other sites More sharing options...
Recommended Posts