• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED Issue with collision and getting stuck

Viciousse

Member
Hello!

I am facing an issue with collision with, since my player is getting stuck while rotating, bellow the code used for movement and collision check:

GML:
//Rotation
var _cc = dcos(image_angle);
var _ss = dsin(image_angle);
var xx = x +  _cc*60 + _ss*20;
var yy = y + _ss*60 + _cc*20;
rotation_dir = point_direction(xx, yy, mouse_x, mouse_y);
image_angle += sin(degtorad(rotation_dir - image_angle)) * rotation_spd;

// Controles

key_up = keyboard_check(ord("Z"));
key_down = keyboard_check(ord("S"));
key_left = keyboard_check(ord("Q"));
key_right = keyboard_check(ord("D"));

h_key = key_right - key_left;
v_key = key_down - key_up;

// Local Vars Movements
var dir = point_direction(0, 0, h_key, v_key);
var move_x = lengthdir_x(mossiba_spd, dir);
var move_y = lengthdir_y(mossiba_spd, dir);

if (h_key != 0 or v_key != 0) {
    
    // Gun
    if (active_weapon == 1) {
        sprite_index = spr_mossiba_gun_walk;
        if (place_meeting(x + move_x, y + move_y, obj_walls_0)) {
            for(var i = 0; i < abs(move_x); i ++) {
                if (!place_meeting(x + sign(move_x), y, obj_walls_0)) {
                    break;
                    x +=sign(move_x);
                }
            }
               move_x = 0
            for(var i = 0; i < abs(move_y); i ++) {
                if (!place_meeting(x, y + sign(move_y), obj_walls_0)) {
                    break;
                    y +=sign(move_y);
                }
            }
            move_y = 0;
        }
    x += move_x;
    y += move_y;
    }
}

// Idle Animation

if (keyboard_check(vk_nokey)) {
    // Gun
    if (active_weapon == 1) {
        sprite_index = spr_mossiba_gun_idle;
    }
}
Please help :|
 

Nidoking

Member
Are you using a circular sprite with precise collision? If not, then rotating the image_angle will also rotate the bounding box.

Also, using sin to get a rotation angle? I guess it still gives you a number, but that's a pretty strange looking way to curve your values between -1 and 1... especially if the angle difference is an obtuse angle, which will slow your rotation down the wider the difference is.
 

Viciousse

Member
Also, using sin to get a rotation angle? I guess it still gives you a number, but that's a pretty strange looking way to curve your values between -1 and 1... especially if the angle difference is an obtuse angle, which will slow your rotation down the wider the difference is.
The sin is because i needed the sprite to shoot from gun canon, i am not facing slow in the rotation for the moment, is there any other way to do that?

Are you using a circular sprite with precise collision? If not, then rotating the image_angle will also rotate the bounding box.
How to do that? :|
 

Nidoking

Member
How to do what? You didn't answer my question, so I don't even know what you're trying to accomplish. The usual method, though, is not to use image_angle, so the bounding box doesn't rotate, and draw the sprite at an angle manually.
 

Viciousse

Member
My bad it was late and i had very hard times with that collision issue, i tryed every possible way i could figur!

Are you using a circular sprite with precise collision?
The sprite is not circular, the collision is precise, and the origin is not centred (custom, since i need to change the sprite a lot, so i had to make it seemless).

How to make my sprite aim at mouse position without using "image_angle"?
 

Nidoking

Member
draw_sprite_ext can be used to draw the sprite at an angle. You calculate the angle the same way you used to. You just don't use the image_angle variable to do it.
 

Viciousse

Member
draw_sprite_ext can be used to draw the sprite at an angle. You calculate the angle the same way you used to. You just don't use the image_angle variable to do it.
To be honest, i have no idea how to do this:
GML:
//Rotation
var _cc = dcos(image_angle);
var _ss = dsin(image_angle);
xx = x +  _cc*60 + _ss*20;
yy = y + -_ss*60 + _cc*20;
rotation_dir = point_direction(xx, yy, mouse_x, mouse_y);
image_angle += sin(degtorad(rotation_dir - image_angle)) * rotation_spd;
With draw_sprite_ext() :[
 

Nidoking

Member
image_angle += sin(degtorad(rotation_dir - image_angle)) * rotation_spd;
This part? This is setting image_angle. You want to NOT set image_angle. Set literally any other variable. Any combination of letters, numbers, and underscores (not starting with a number) that is not the exact name "image_angle". You can use my_image_angle. You can use hello_this_is_my_angle. You can use dgvabioreunwgriouanjrfolwrugnveirnvafolribgvifc for all that it matters. Just DO NOT ASSIGN A VALUE AT ALL to image_angle. Use this new variable that you've created in every place where you're currently using image_angle, because you never want to change image_angle.
 

Viciousse

Member
This part? This is setting image_angle. You want to NOT set image_angle. Set literally any other variable. Any combination of letters, numbers, and underscores (not starting with a number) that is not the exact name "image_angle". You can use my_image_angle. You can use hello_this_is_my_angle. You can use dgvabioreunwgriouanjrfolwrugnveirnvafolribgvifc for all that it matters. Just DO NOT ASSIGN A VALUE AT ALL to image_angle. Use this new variable that you've created in every place where you're currently using image_angle, because you never want to change image_angle.
Well i did it, remplace image_angle with _image_angle; what happend is:
  • My sprite dont rotate
  • I still can shoot to mouse_x and mouse_y (without rotation)
  • The collision is working fine
How can I manage to have rotation without image_angle?
 
Top