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

GML Visual When mouse pressed - move object to that point on screen ( D&D )

P

pastelspirit

Guest
Hi all!

I'd like to control my character movement via mouse. So when I click somewhere on screen, the object should move towards that point.
Also some pathfinding option maybe? So that it avoids walls or "forbidden spots" in his way and goes around them..

Can I do this without any code in D&D?
I appreciate any good pointers. Thank you!
 

matharoo

manualman
GameMaker Dev.
So you are saying it is not possible wit D&D?
I don't know, I do not use D&D. But I know that if you are serious about making a game, D&D is not worth using.
If it were possible in D&D by any means, it would a hard and tedious job.
 
P

pastelspirit

Guest
Since I'm no coder at all, it is already hard and tedious and I like the idea of D&D much better. :D
 
J

JFitch

Guest
With D&D, you can only avoid solid objects or all objects. You'll have to use code to avoid a specific object.

In the create event,
Code:
target_x=x
target_y=y
In the left mouse pressed event,
Code:
target_x=mouse_x
target_y=mouse_y
In the step event, use the Step Avoiding function to step toward the point (target_x, target_y), set the speed to however fast you want it to move, and choose whether you want to avoid all objects or just solid objects. If you choose solid objects, make sure you check the "solid" box for that object.
 
P

pastelspirit

Guest
Ok, now my character is moving with mouse clicks. Thanks for the pointers!
Now I need to be able to check if the click happened on an object (which results in the character moving to and stopping at a specific coordinate at the object sprite).
 
P

pastelspirit

Guest
That's done too.
Now I need to be able to tell Studio, where I clicked on the screen in relation to the player character. Left, right, up or down...and when starts moving it should change sprite animation according to the direction it is moving.

Also is there a way to make the Step Avoiding function to do stationary intitial direction change at the beginning and not circle around and then move to the clicked direction?
 
J

JFitch

Guest
Code:
(point_direction(x,y,mouse_x,mouse_y)+45) div 90
This will give you right for 0 or 4, up for 1, left for 2, and down for 3.
 
Last edited by a moderator:
Top