Object behavior is all the same.

This is my object spawner, which I'm currently testing with to help me understand controlling objects better.

Code:
if alarm[0]==-1
{
   var inst_1
   inst_1 = instance_create_layer(irandom_range(200,1910), 200, layer, obj_Enemy_1);
   inst_1.speed = choose(1,9);
   inst_1.image_angle = choose(-10,+10);

   alarm[0] = room_speed * 1
}
However, when I run it all the objects are behaving exactly the same. I've also tried it using the "with" constructor as follows:

Code:
if alarm[0]==-1
{
   var inst_1
   inst_1 = instance_create_layer(irandom_range(200,1910), 200, layer, obj_Enemy_1);
   
     with inst_1
     {
     speed = choose(1,9);
     image_angle = choose(-10,+10);
     }

   alarm[0] = room_speed * 1
}
Shouldn't each inst_1 get a speed of 1 or 9 and an image angle that is either -10 or +10? I've read through a few articles and I think it should work! Please help me understand why it's not working.
 
This is in the step event of the enemy.

Code:
move_towards_point(obj_Player1.x, obj_Player1.y, 1)
point_direction(x, y, obj_Player1.x, obj_Player1.y);
 
However, when I run it all the objects are behaving exactly the same
I assume you mean that they are all created in the same location, and have the same speed and image_angle.
Have you used the function randomise() anywhere at the start of your game? Without that GMS will always calculate the same random number used in your irandom_range, and will always select the same thing in the choose function too. If you have not called that at the start of your game, then do it and see if that makes a difference.
 
I assume you mean that they are all created in the same location, and have the same speed and image_angle.
Have you used the function randomise() anywhere at the start of your game? Without that GMS will always calculate the same random number used in your irandom_range, and will always select the same thing in the choose function too. If you have not called that at the start of your game, then do it and see if that makes a difference.
They are all created in different locations, but with the same speed and image angle.

I've changed the code to the following:

Code:
if alarm[0]==-1
{
   var inst_1
   inst_1 = instance_create_layer(irandom_range(200,1910), 200, layer, obj_Acid_Ooze_1);
   inst_1.speed = random(9);
   //inst_1.image_angle = choose(-10,+10);

   alarm[0] = room_speed * 1
}
I've messaged out image angle to see if at least the speed becomes random. However, all enemies still move at the same speed.
 

FrostyCat

Member
This is the line in the enemy's Step event where you overwrote the randomized speed with 1:
Code:
move_towards_point(obj_Player1.x, obj_Player1.y, 1)
Instead of that, leave the speed alone and change just the direction:
Code:
direction = point_direction(x, y, obj_Player1.x, obj_Player1.y);
 

TheouAegis

Member
Well you're only dealing with a difference of 20 degrees with that image_angle range, but it should still be kinda noticeable. Do you have anything in the enemy's Draw event?
 
Top