• 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!

Change object depth based on mouse position

A

Arthur_echoes

Guest
Im making a game project (still learning) and im trying to make an obj "sword" change depth when the mouse is in north of the screen.

i did it as a similar thing when i made the obj "player" change xscale on mouse position



//xscale on cursor//
var mouse_dir;

mouse_dir = point_direction(o_player.x, o_player.y, mouse_x, mouse_y);
if mouse_dir > 90 and mouse_dir < 270 {
o_player.image_xscale = -1;
} else {
o_player.image_xscale = 1;
}



with the obj "sword" i tried a similar thing but it didn't worked



// depth on mouse position
var mouse_dir;

mouse_dir = point_direction(o_player.x, o_player.y, mouse_x, mouse_y);
if mouse_dir < 0 and mouse_dir > 0 and mouse_dir <90 and mouse_dir >270{
object_set_depth (o_sword,1)
} else {
object_set_depth (o_sword,0)
}
 

Simon Gust

Member
You're asking
if mouse_dir is less than 0 and more than 0 at the same time.
and
if mouse_dir is less than 90 and more than 270 at the same time.

You might notice that this is physically impossible to achieve unless you had some sort of quantum computer.
This causes your statement to always return false, setting the depth to 0.

Also, where exactly is your north? From the code you supplied, you'd rather check for east.

Is there a reason you don't want to just check if the mouse is above the player, then it is in the north technically speaking.
 
A

Arthur_echoes

Guest
You're asking
if mouse_dir is less than 0 and more than 0 at the same time.
and
if mouse_dir is less than 90 and more than 270 at the same time.

You might notice that this is physically impossible to achieve unless you had some sort of quantum computer.
This causes your statement to always return false, setting the depth to 0.

Also, where exactly is your north? From the code you supplied, you'd rather check for east.

Is there a reason you don't want to just check if the mouse is above the player, then it is in the north technically speaking.
i know, i tried every single number and it didn't worked, disconsider that line
 

Simon Gust

Member
Consider this


You want north. North begins at 0 and ends at 180.
Code:
var mouse_dir;

mouse_dir = point_direction(o_player.x, o_player.y, mouse_x, mouse_y);
if (mouse_dir > 0 and mouse_dir < 180)
   object_set_depth (o_sword,1);
} else {
   object_set_depth (o_sword,0);
}
 
A

Arthur_echoes

Guest
Consider this


You want north. North begins at 0 and ends at 180.
Code:
var mouse_dir;

mouse_dir = point_direction(o_player.x, o_player.y, mouse_x, mouse_y);
if (mouse_dir > 0 and mouse_dir < 180)
   object_set_depth (o_sword,1);
} else {
   object_set_depth (o_sword,0);
}
oooh i tought the 0 degree was at the north...
i tried to use this line"" if (mouse_dir > 0 and mouse_dir < 180)""
but with 270º and 90º
 
A

Arthur_echoes

Guest
it didn't worked, but with that information i can make it work some wayp_playernotwork.PNG splayernotwork.PNG
 
Top