GMS 2.3+ Better Enemy Laser?

So I've made an enemy laser that is 1 x 20. I want it to be constantly facing in the direction it is going. I have the point set up on it middle center. Problem is, the laser isn't always pointing the direction it's going. The enemies shoot it and it will update it's angle mid-flight. It's the best I've come up with from my puny little brain. I know there has to be a better way. Any ideas?

This is how I've done it. Step event:

if instance_exists(obj_enemy_laser){
image_angle = obj_enemy_laser.direction;

Your help is much appreciated.


Your code is a little confusing as we don't know the context. What are you setting the angle of? It's apparently not the laser since you are referring to the laser as a separate instance.

But hey, none of it matters. Wherever you set the direction of the laser, set the image angle to the same. Done. Assuming the laser doesn't change directions midflight, it should be good.

Also you might want to set the origin to the head of the laser instead of the middle unless you want it to pass halfway through things it collides with.
I am trying to set the angle of the laser as it is shot from the enemy. It needs to be facing the direction it's going. Sorry if I made it confusing. I'll have to try setting the origin to the head of the laser though and see what that does.


Well if the laser has a step event just put image_angle=direction in it, but better to set it once when you create the laser.


Learn the difference between objects and instances.
Created or copied instance. instance_create() (GMS 1.x and legacy) / instance_create_layer() and instance_create_depth() (GMS 2.x) and instance_copy() return the ID of the created or copied instance. NEVER use instance_nearest() to establish this relationship --- something else could be closer by.
var inst_bullet = instance_create_layer(x, y, layer, obj_bullet);
inst_bullet.direction = direction;
inst_bullet.speed = 5;
Subsidiary instance(s). Same as created or copied instance. If the subsidiary instance needs to reference its creator, the creator should assign its instance ID to an instance variable in the subsidiary instance. Conversely, if the creator needs to reference its subsidiary (or subsidiaries), it must store the return value of instance_create() (GMS 1.x and legacy) / instance_create_layer() or instance_create_depth() (GMS 2.x) immediately. NEVER use instance_nearest() to establish or maintain this relationship --- being the closest does NOT imply being the most relevant, especially in close quarters.
my_pet = instance_create_layer(x+32, y, layer, obj_pet);
my_pet.owner = id;
Get rid of the code shown in your opening post. Then set the angle once when you create the instance of obj_enemy_laser, and leave it at that.
with (instance_create_layer(x, y, layer, obj_enemy_laser)) {
    direction = other.direction;
    image_angle = direction;
    speed = 5;