GameMaker Space Rocks GML Gravitating Asteroids Bug(?) [SOLVED (Kinda)]

M

mario_head

Guest
So I've made it through setting up the collisions and such.
Player has attacks, everything moves and explodes and splits as necessary, as well as movement wrapping being successfully implemented.
However, I've got one issue I've noticed, a particularly funny one imo, with one of the size variants of Asteroid.
For the "Huge" variant, I was feeling lazy, and decided, instead of drawing up another Asteroid, I'd just, as a joke, make a Sans head as an Asteroid (Which admittedly took much longer than the former).
So, what's confusing here, is that when I run the game, any and all instances of the Huge Asteroid will seem to gravitate towards the nearest object. I did see a similar post concerning the Asteroids changing direction while rotating, but looking closer I can definitely conclude that the Huge Asteroid is targeting nearby objects, as it slows and changes direction after wrapping.

I am running IDE Version 2.2.5.481

Code:
obj_argo ///(Ship/Player Object)
Step ///Movement & Attack Creation
    if(keyboard_check(vk_left)){
        image_angle = image_angle + 5; ///Turns the Object Left
    }

    if(keyboard_check(vk_right)){
        image_angle = image_angle - 5; ///Turns the Object Right
    }

    if(keyboard_check(vk_up)){
        motion_add(image_angle, 0.05); ///Adds Set Value of Motion
    }

    if(keyboard_check_pressed(ord("Z"))){
        var inst = instance_create_layer(x,y, "Instances", obj_atk2); ///Creates Attack
        inst.direction = image_angle; ///Sets the Attack to fire from the Object's Front
        inst.image_angle = image_angle; ///Sets the Attack Angle to the Object Angle
    }

    if(keyboard_check(vk_escape)){ ///(This is here for later when I was going to have set up an input to close the game)
    
}
    move_wrap(true,true,sprite_width/2); ///Wraps the Object when passing the screen boundary

Collision with obj_aster1 (The Asteroid Object)
    instance_destroy();
   
    repeat(10){
        instance_create_layer(x,y,"Instances", obj_debris);

obj_aster1 (The Asteroid Object)
Create ///Positioning and Movement
    
    sprite_index = choose( ///Chooses Sprite from inputted catalog
        spr_aster1, (Medium Asteroid)
        spr_aster2, (Huge/Sans Asteroid, the one Targeting other Objects)
        spr_aster3  (Small Asteroid)
    );

    direction = irandom_range(0,359); ///Chooses a random direction (0=360)
    image_angle = irandom_range(0,359); ///Chooses random image position (0=360)

    speed = 1;

Step ///Wrap & Rotate
    move_wrap(true,true,sprite_width/2); ///Wraps the Object when passing the screen boundary
    image_angle = image_angle + 1;

obj_atk2 (The Bullet, numbered because I am planning to implement a few different Attacks)
Create ///Speed
    speed = 6;
Collision with obj_aster1
    
    instance_destroy();

    with(other){
        instance_destroy();
    
        if(sprite_index == spr_aster2){
            repeat(2){ ///Makes the sprite split into two
                var new_aster = instance_create_layer(x,y, "Instances", obj_aster1);    
                new_aster.sprite_index = spr_aster1;         
             }
        }
        else if(sprite_index == spr_aster1){
            repeat(4){ ///Makes the sprite split into two (I chose 4 out of preference, and yes, I do realize the comment says two instead of four)
                var new_aster = instance_create_layer(x,y, "Instances", obj_aster1);    
                new_aster.sprite_index = spr_aster3;         
            }
        }
    
        repeat(4){
            instance_create_layer(x,y,"Instances", obj_debris);
        }
    }
    ///WHY DOES SANS HAVE AIMBOT (Comment left in)
Outside Room
    instance_destroy();
I would have included the coding for the Debris Object, but I know that is not relevant, as it had been coded in after discovery.
I've also looked over the coding quite a few times, and everything seems to match what the tutorial shows (Although I have been known to miss silly little differences multiple times)
 

Nidoking

Member
I don't see any obvious problems, but maybe the sprite_width of the sprite you're using is big enough to mess with the move_wrap calculation. What if you replace it with a different sprite, maybe a scaled version of one of the sprites that work? It looks like the object is exactly the same and the only thing different is the sprite, so I find it hard to imagine that it's anything else.
 
M

mario_head

Guest
I don't see any obvious problems, but maybe the sprite_width of the sprite you're using is big enough to mess with the move_wrap calculation. What if you replace it with a different sprite, maybe a scaled version of one of the sprites that work? It looks like the object is exactly the same and the only thing different is the sprite, so I find it hard to imagine that it's anything else.
I just tried drawing up a new sprite entirely (The Sans head sprite was 58x60 or something so I can see how that might create issues) at 64x64, no change. I then tried importing the medium Asteroid sprite with the same result.
It seems the problem might be elsewhere? This is quite a confusing little bugger lol
 
M

mario_head

Guest
I suspect "elsewhere", but you'll have to post the elsewhere part before I can try to guess what it is.
The only other object that currently exists and possesses coding is obj_debris, but I'll post that here:
Code:
obj_debris
Create
    
    direction = irandom_range(0,359);
    speed = 1;

Step

    image_alpha = image_alpha - 0.01;
        if(image_alpha <= 0){
            instance_destroy();
        }
 

Nidoking

Member
Hmmm... yeah, nothing here seems out of place. The closest thing I can see to a likely error is that in the collision event between the bullet and the asteroid, you're doing instance_destroy and then referring to variables in the instance that no longer exists. But that should just crash the game. All I can assume is that there's something more to your game that you're not posting. Try cleaning the cache, maybe.
 
M

mario_head

Guest
The only other assets that currently exist are sprite files that aren't in used and the room file. I'm not sure how to clear cache with GMS2 (I Googled and so far have only found instructions via GMS1), but given timeframes, I likely won't be able to do so/have any updates until later tonight when I get off work.
 
M

mario_head

Guest
The only other assets that currently exist are sprite files that aren't in used and the room file. I'm not sure how to clear cache with GMS2 (I Googled and so far have only found instructions via GMS1), but given timeframes, I likely won't be able to do so/have any updates until later tonight when I get off work.
I'm still not too sure on how to clear cache, but I wouldn't particularly know if it would help given this is my first project with GMS2.
I'm thinking what I could do is mess around and turn the large asteroid into a spaceship of some sort, so that the targeting makes sense.
 
M

mario_head

Guest
on the right of the run button the second button looking like a brush (called clean when you mouse hover it) else you can just CTRL+F7
Thanks, I had a feeling it would be painfully obvious lol
Unfortunately the Cleaning did not resolve the issue, so I'll just have to go through with converting the asteroid into a spaceship
 
Top