# GMLscripts.com

Discuss and collaborate on GML scripts

You are not logged in.

## #1 2010-08-25 13:55:59

BlueMoonProductions
Member
Registered: 2010-08-25
Posts: 22

### move_to_mouse

Hey,

I've got some things to say about move_to_mouse.
First of all, the name of the script is wrong(in my opinion), it should be 'jump_to_mouse'. A good 'move_to_mouse' script would be:

/// move_to_mouse(speed)
if point_distance(x,y,mouse_x,mouse_y)<argument0
{
x = mouse_x;
y = mouse_y;
}else{
var dir;
dir = point_direction(x,y,mouse_x,mouse_y)
x+= lengthdir_x(argument0,dir)
y+= lengthdir_y(argument0,dir)
}

Because you really move using this script.

The second thing, why did you put this 'script' on the site? I mean, it's just too simple, everyone could make it, it's just assigning some variables, right?
Maybe beginners don't know the variable-name's, but GMLscripts is not for basic scripts(correct me if I am wrong).
I think this script is too simple to be in the GMLscripts library(whatever it's called).

Blue

Offline

## #2 2010-08-25 20:26:01

icuurd12b42
Member
Registered: 2008-12-11
Posts: 303

### Re: move_to_mouse

more streamlined

var dir;
var dist;
dir = point_direction(x,y,mouse_x,mouse_y)
dist = min(point_distance(x,y,mouse_x,mouse_y),argument0)
x+= lengthdir_x(dist,dir);
y+= lengthdir_y(dist,dir);

the other, a speed based method

direction = point_direction(x,y,mouse_x,mouse_y)
speed = min(point_distance(x,y,mouse_x,mouse_y),argument0)

Offline

## #3 2010-08-25 22:23:24

xot
Registered: 2007-08-18
Posts: 1,201

### Re: move_to_mouse

Those are some good points, Blue.

I agree, jump_to_mouse is the best name for that function. That name is in the style of the Game Maker reference, which is what I prefer.

For the new function, I'm going to recommend calling it move_towards_mouse, which is also more in the style of Game Maker, and is less ambiguous than move_to_mouse. I believe it should use the speed/direction method provided by icuurd12b42 because that is how the Move Towards action works.

I think the other method of setting x and y directly should be called step_towards_mouse because it works like the Step Towards action.

As for the reason the script appears at all, I did give it some serious thought. At first I was going to toss this script out when it was submitted, but as I explained to the submitter, I've decided to keep it because I believe it demonstrates good coding practice by abstracting a process by using a function with a descriptive name. Maybe I should add a note to that effect on the script page.

Abusing forum power since 1986.

Offline