GML need help with Direction

J

jaber

Guest
hi,
very straight forward ... how do I get a normal vector direction to my player direction?
draw_text(924, 220, "point direction >" + string(point_direction(x, y, mouse_x, mouse_y))); // this is my player direction
1598647653013.png

I want the direction of a normal so that I can move the bullet cases always to the player left side
I tried just adding 90 to the player direction but that does not work in all direction
draw_text(924, 240, "point direction + 90 >" + string( point_direction(x, y, mouse_x, mouse_y) + 90));

please help
thanks
J
 
S

Seknight

Guest
in what directions does it not work? can you post the code for the casing?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
IF you are setting the image_angle or direction then simply adding/subtracting 90 should be fine. The angle shown maybe something like 450, but GM will still interpret that correctly. You say you already tried this, but did you actually try it or are you just printing out values and assuming it's wrong? And if you did try it and it didn't work, what was the code? I use this in my game Alpha Dog to send off shell casing when firing the mini-gun and it works fine:

GML:
with (instance_create_layer(_x, _y, "Floor_Instances", obj_Debris))
    {
    sprite_index = spr_Pixel;
    image_index = 0;
    direction = other.dir - 90; // <------- direction - 90 works fine...
    speed = 2 + random(2);
    friction = 0.5;
    }
 

Joe Ellis

Member
Normals and vectors are easier to understand when you realize they're basically the same as how hspeed and vspeed work.
A vector is a direction defined by coordinates, the same as 2 speed variables for each axis. It's easy to see and understand what direction an object will move in when the hspeed is 1 and the vspeed is 3, it will be going diagonally but more downwards than horizontal. And you can actually see what direction it will be moving in in your head.

To create a normal from a direction the simplest way is to use lengthdir_x & y:
GML:
///angle_to_normal(angle)

var n = {};

n.x = lengthdir_x(1, angle)
n.y = lengthdir_y(1, angle)

return n
 
J

jaber

Guest
IF you are setting the image_angle or direction then simply adding/subtracting 90 should be fine. The angle shown maybe something like 450, but GM will still interpret that correctly. You say you already tried this, but did you actually try it or are you just printing out values and assuming it's wrong? And if you did try it and it didn't work, what was the code? I use this in my game Alpha Dog to send off shell casing when firing the mini-gun and it works fine:

GML:
with (instance_create_layer(_x, _y, "Floor_Instances", obj_Debris))
    {
    sprite_index = spr_Pixel;
    image_index = 0;
    direction = other.dir - 90; // <------- direction - 90 works fine...
    speed = 2 + random(2);
    friction = 0.5;
    }
Thanks So much.. that is exactely what worked for me.
 
J

jaber

Guest
Normals and vectors are easier to understand when you realize they're basically the same as how hspeed and vspeed work.
A vector is a direction defined by coordinates, the same as 2 speed variables for each axis. It's easy to see and understand what direction an object will move in when the hspeed is 1 and the vspeed is 3, it will be going diagonally but more downwards than horizontal. And you can actually see what direction it will be moving in in your head.

To create a normal from a direction the simplest way is to use lengthdir_x & y:
GML:
///angle_to_normal(angle)

var n = {};

n.x = lengthdir_x(1, angle)
n.y = lengthdir_y(1, angle)

return n
thanks.... u made vectors more clear for me : )
 
Top