Hosting and domain costs until October 2024 have been generously sponsored by dumptruck_ds. Thank you!

Difference between revisions of "movetogoal"

From Quake Wiki

(Created page with "====Syntax:==== <code>void movetogoal(float dist)</code> This is the primary means of navigation available to monsters. It is a very basic form of navigation consisting of o...")
 
m (Usage)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
====Syntax:====
+
''void'' '''movetogoal'''(''float'' dist)
<code>void movetogoal(float dist)</code>
 
  
This is the primary means of navigation available to monsters.  It is a very basic form of navigation consisting of only 2 behaviours:
+
== Usage ==
1. Move straight toward the current''' .goalentity'''
+
Attempts to move an entity towards its '''goalentity''' field. This function only supports movement in 8 directions (North, Northeast, East, Southeast, South, Southwest, West, and Northwest). If the entity's movement is blocked it will try and redirect itself to keep moving towards its goal. Movement is only done on the x and y axes. This does not sweep the movement area so large steps should be broken down into smaller parts, otherwise missed collisions can occur.
2. If blocked, move in a random direction for a random period of time.
 
If the monster has the '''FL_FLY''' flag set, it will try to stay slightly above the height of the entity in the '''.enemy''' field.
 
====Parameters:====
 
:<code>dist</code> - How far to 'step'.
 
====Returns:====
 
:void
 
====Other Details:====
 
Please note that the movement target and the height target are set via ''different'' fields. Setting '''.goalentity''' but not '''.enemy''' will result in a monster not adjusting it's height.
 
However, merely setting '''.enemy''' to an entity is not enough for movetogoal to match heights with it.  The entity in the '''.enemy''' field must have a bounding box (it cannot be a point entity) and it must also have a '''.movetype''' other than '''MOVETYPE_NONE''').
 
  
 +
If an entity can fly or swim, it will attempt to level itself with its enemy, not the goal entity. If it can't fly or swim and is off the ground, it won't move at all. If an entity is too close to its goal it'll also stop moving.
 +
 +
'''Warning:''' The function assumes that '''self''' is the current entity trying to move.
 +
 +
=== Parameters ===
 +
*''dist''
 +
:How far the entity should move in map units.
 +
 +
== Example ==
 +
// Slow down movement as the monster gets closer to its enemy
 +
float multi = enemy_range / RANGE_MID;
 +
if (multi < 0.5)
 +
    multi = 0.5;
 +
else if (multi > 1)
 +
    multi = 1;
 +
 +
movetogoal(32 * multi);
  
 
[[Category:QuakeC Function]]
 
[[Category:QuakeC Function]]

Latest revision as of 17:14, 1 August 2023

void movetogoal(float dist)

Usage[edit]

Attempts to move an entity towards its goalentity field. This function only supports movement in 8 directions (North, Northeast, East, Southeast, South, Southwest, West, and Northwest). If the entity's movement is blocked it will try and redirect itself to keep moving towards its goal. Movement is only done on the x and y axes. This does not sweep the movement area so large steps should be broken down into smaller parts, otherwise missed collisions can occur.

If an entity can fly or swim, it will attempt to level itself with its enemy, not the goal entity. If it can't fly or swim and is off the ground, it won't move at all. If an entity is too close to its goal it'll also stop moving.

Warning: The function assumes that self is the current entity trying to move.

Parameters[edit]

  • dist
How far the entity should move in map units.

Example[edit]

// Slow down movement as the monster gets closer to its enemy
float multi = enemy_range / RANGE_MID;
if (multi < 0.5)
    multi = 0.5;
else if (multi > 1)
    multi = 1;

movetogoal(32 * multi);