Windows New to gamemaker need some help.

S

Scared Sacred

Guest
This is probably really easy but i cant seem to get it right (i'm using drag and drop). what i'm trying to do is make my object change into the other objects depending on where the mouse is. I have 4 objects i want to use. I almost have it down it changes to the back, left, and front version of the object but not to the one facing right.

I started out using a step event and having my characters movement, after that i have a declare temp. and i put dir for the name and point_direction(x, y, mouse_x, mouse_y) under value. After that is an if variable dir is greater than 45 , and then another if variable is less than or equal to 135 it will change instance to my object which faces the back. After that i have an else statement which is the same as above but it changes the angles and the object to face the correct way. When i put the object in the room and test it the character changes to only the back left and front model and i don't know whats wrong.

Sorry if this is a dumb request, but i'm new to this and don't know exactly what i'm doing. I would really appreciate some help here. I have attached a screenshot of what I have so far.
 

Attachments

Last edited by a moderator:
I am not sure I understand, you want your object to change depending on the direction ?
I think I would rather go about it like this :

var mouse_dir ; mouse_dir = point_direction(x, y, mouse_x, mouse_y) ; //var is used so that after the step event the variable is discarded freeing memory (I think)
if mouse_dir > 45
{
//do something
}
else
{
if mouse_dir <= 135
{
//do something
}
else
{
//etc
}
}

In your exemple if you write:
if a > 45 do b
if a <= 135 do c
the issue will be that between 45 and 135 result will be b, so I am not sure what you are trying to do.
 
S

Scared Sacred

Guest
i put it in the screen shot i'm pretty sure i had it like you said but it still doesn't work for the 315-45 right side object
 

samspade

Member
I haven't actually done anything with drag and drop, but I think that what you want to do is accomplished pretty easy through some simple code. If I understand it correctly, what you want to do is the following: affect the object depending upon its direction to the mouse pointer. I assume you're using the objects direction in the code.

Code:
//object step event

var dir = point_direction(x, y, mouse_x, mouse_y);
var angle_to_mouse = angle_difference(direction, dir);
if (angle_to_mouse > 45) && (angle_to_mouse < 135) {
     //mouse is to the left
} else if (angle_to_mouse < -45) && (angle_to_mouse > -135) {
    //mouse is to the right
} else if (angle_to_mouse > 135) || (angle_to_mouse < -135) {
    //mouse is behind   
} else {
    //mouse is ahead
}
This should, if I did my math correctly, create it dynamically based upon the direction. Essentially it gets the angle to the mouse pointer and then compares the difference between that angle and the objects direction. 1 through 180 would be the left (counterclockwise), and -1 through -180 is to the right (clockwise). It doesn't go higher (I believe but haven't tested this) than 180 or lower than -180 so saying >135 and < -135 shouldn't cause a problem.

I'm also assuming that you are actually changing objects for a reason, not just changing the sprite and the character's animation. In other words, you move with left, right, up, and down, but you have different abilities or something based upon where the mouse is in relation to the object verses you move with left, right, up, and down, and all you want is your character to look in that basic direction, in which case there are far simpler solutions.
 
Top