In my Gamemaker: Studio game, I have a collision script for my enemy. The enemy is an alien, oSwarmer
, moving through space which is also filled with drifting, spinning bits of debris. Some debris barely spins at all, others spin quite fast.
When oSwarmer
executes the following collision script every step. As you can see, if it is about to come into contact with some debris (here called oSolid
) it changes direction away from the colliding oSolid
and maintains its original speed.
SolidTouching = instance_place(x + hspeed, y + vspeed, oSolid)
if instance_exists(SolidTouching) {
OriginalSpeed = CurrentSetSwarmerSpeed
if speed > 0 {
direction = direction - random_range(130,220)
} else if speed <= 0 {
direction = point_distance(x,y,SolidTouching.x,SolidTouching.y) - random_range(130,220)
}
speed = OriginalSpeed
}
However, sometimes when coming into contact with an oSolid
, they spin madly on the spot. I've noticed that this seems to occur when the oSolid
is spinning. These creatures do not move very fast, so their initial 'bounce' is not enough to carry them out of the path of the rest of the oSolid
which is coming around to meet them. I think they then get caught in a loop of constantly trying to move in the opposite direction to the colliding oSolid
(which is changing every step because it is spinning).
What I cannot work out is how to remedy this. Does anybody have a suggestion?
speed
change bothxspeed
andyspeed
values(based ondirection
ofc). \$\endgroup\$120 / room_speed
. Point Distance is a Gamemaker function for getting the distance in pixels between two points, but I now realise I've been using it wrong! I meant to usepoint_direction
. That fix doesn't help, tho. \$\endgroup\$