GameMakerHelpBlog

Saturday, November 25, 2006

Moving Mouse 3 - RTS style

This is an RTS style movement system , can be used for topdown too...

This has more than one part to it so we will go through it 1 by 1
1. In create event (stuff the color coding for this turtorial) Put this code
[code]
target_x=x;
target_y=y;
[/code]
(oh i should say don't add the code tags)
This code above should init the target variables for your guy to move too.
2. In step event This code checks whether you have met your mouse clicked position put this code
[code]

/ If we didn't reach the target pos yet..
dist=point_distance(x, y, target_x, target_y);
if(dist>0) {
// Move towards it.
direction=point_direction(x, y, target_x, target_y);
speed=min(dist, 4);
} else {
// Otherwise stop moving.
speed=0;
}
[/code]
3. In global.left pressed in mouse event. This code will move you to the target Put this code
[code]
//argument0 = player object or allied
(argument0).target_x=mouse_x; //player object = argument0
(argument0).target_y=mouse_y;

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home