GML Wall Crawling On Curved Surfaces, clockwise and counter, directional ascent

How would I do a wall crawling enemy that can handle curved surfaces and go 360 degrees around them, rotate it's sprite (not necessarily the mask), switch movement direction from clockwise to counter clock wise or stop when I tell it to, and jump in the direction of relative up from it's base when I tell it to (no gravity necessary just continued ascent until finding a wall again)?
 

gmx0

Member
First, have it detect which block (curved surface) it is on with a collision function.

Use image_angle and point_direction to rotate the sprite towards the block. image_angle and other direction functions are 0-360.

0 is east, 90 is north, 180 is west, 270 is south.

image_angle and direction variables go counterclockwise by adding, and clockwise by subtraction.

To jump, add speed to the point_direction to the block plus 180 (or the point_direction from block to enemy)

So translating that into code:
Create Event:
Code:
block=noone;
block_dir=0;
Collision Event with block object/curved surface object:
Code:
block=other.id;
block_dir=point_direction(x,y,block.x,block.y);
Step Event:
Code:
if instance_exists(block)
{
image_angle=block_dir-90; //Assuming this is a platformer sprite, and not top down sprite

//put it in the center to detect surface
x=block.x;
y=block.y;
//drag object to the outside so it looks like it is on the curve
 do
 {
 x+=lengthdir_x(1,block_dir+180);
 y+=lengthdir_y(1,block_dir+180);
 }
 until
 !instance_place(x,y,block);
}
Left(Counter Clockwise) code:
Code:
block_dir+=1 mod 360; //replace 1 with speed
Right (Clockwise) code:
Code:
block_dir-=1 mod 360; //replace 1 with speed
Up/Jump event/code:
Code:
if instance_exists(block)
{
direction=point_direction(block.x,block.y,x,y);
speed=10; //INSERT WHATEVER SPEED YOU WANT
block=noone;
}
Probably gonna be funky, but adapt it to your game.
 
Last edited:
Top