• Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!

GMS 2 [Solved] Randomly picking an instance's direction



I'm trying to make a set of projectile objects move toward a set of deflector object instances. The deflectors are arranged in a circle after being spawned through a for loop. It seems to be working except for an issue where the deflected projectiles do not randomize and only choose to move towards one of the deflector object instances (probably the first one created thru the for loop).

The setup is as follows. A player object creates a set of deflector object instances linked to it:

def_inst.myid=myid; //myid being the main controller for the player, deflector and projectiles.

After creating the projectile instances, they are programmed to spawn within the deflector instances arranged in a circle and choose a direction pointing towards one of the deflectors, randomly. It works fine up to this point. Now when the projectile moves toward a deflector and collides with it, I want it to change direction to point towards any of the other deflectors (not the one it just collided with). The end result should be the projectiles colliding against the deflectors and criss-crossing within the circle formation.

The projectile code for colliding with the deflector:

if can_deflect==1
    alarm[0]=4 //reset can_deflect
    var inst = instance_find(myid.def_inst, irandom(instance_number(myid.def_inst) - 1));
As I said earlier, the problem is, after colliding with the deflectors initially, instead of randomly picking and moving towards any other deflector's direction, the projectiles move towards one only.

Is there any way to achieve this?

Any guidance is appreciated. Thanks!
Last edited: