GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2013-12-02 07:08:38

FreePalestine
Member
Registered: 2013-12-02
Posts: 3

Directed rockets (homing)

Expand/*
**  Usage:
**      turn_to_position(x_tar,y_tar,max_deg)
**
**  Arguments:
**      x/y_tar      position to Direct to
**      max_deg   the max degree to rotate by step
**
**
**  Returns:
**      return if direction=point_direction(x,y,x_target,y_target)
**
**  Notes:
**      This Is The function That Used By The Most Of Games To Make
**      A Roket Follw A Target Automatically With Smooth Method
**      And It Used For More Other Things
**      But This Is A Short Script I Make It
*/

{
    var ROT; ROT=point_direction(x,y,argument0,argument1)
    
    if abs(ROT-direction)<=argument2 {direction=ROT; return 1} else
    {
        var TMP; TMP=ROT-direction; if TMP<0 TMP+=360
        if TMP>180 {direction-=argument2; if direction<0 direction+=360}
        else {direction+=argument2; if direction>=360 direction-=360}
        return 0
    }
}

Last edited by FreePalestine (2013-12-04 11:17:36)

Offline

#2 2013-12-02 07:10:47

FreePalestine
Member
Registered: 2013-12-02
Posts: 3

Re: Directed rockets (homing)

Example:

create_event:

Expandspeed=5

Step_event

Expandturn_to_position(mouse_x,mouse_y,5)
image_angle=direction

Last edited by FreePalestine (2013-12-04 11:19:23)

Offline

#3 2013-12-02 07:14:44

FreePalestine
Member
Registered: 2013-12-02
Posts: 3

Re: Directed rockets (homing)

another form to the script
this is a general form:

Expand//turn_dir_to_dir(dir1,dir2,speed)

if abs(argument0-argument1)<=argument2 return argument1
var TMP; TMP=argument1-argument0; if TMP<0 TMP+=360
if TMP>180 {TMP=argument0-argument2; if TMP<0 return TMP+360}
else {TMP=argument0+argument2; if TMP>=360 return TMP-360}
return TMP

Example:

Create_Event:

Expandspeed=5

Step_Event:

Expanddirection=turn_dir_to_dir(direction,point_direction(x,y,mouse_x,mouse_y),5)
image_angle=direction

Last edited by FreePalestine (2013-12-04 11:13:56)

Offline

#4 2013-12-08 22:57:01

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

Re: Directed rockets (homing)

image_angle+=median(-5,angle_difference(point_direction(x,y,mouse_x,mouse_y),image_angle),5);
or
image_angle+=lengthdir_y(5, image_angle - point_direction(x,y,mouse_x,mouse_y));

Last edited by icuurd12b42 (2013-12-08 22:58:54)

Offline

Board footer

Powered by FluxBB