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

Difference between revisions of "droptofloor"

From Quake Wiki

(Created page with "====Syntax:==== <code>float droptofloor(float yaw, float dist)</code> Tries to "drop" an entity down up to 256 units in a single frame, as if it had fallen due to physics. ==...")
 
 
Line 1: Line 1:
====Syntax:====
+
''float'' '''droptofloor'''()
<code>float droptofloor(float yaw, float dist)</code>
 
  
Tries to "drop" an entity down up to 256 units in a single frame, as if it had fallen due to physics.
+
== Usage ==
====Parameters:====
+
Tries to move an entity to the nearest floor beneath it, up to 256 map units. This is mostly for snapping item and monsters to the ground at map start, but this function shouldn't be called within the initializer functions themselves. Not all entities are guaranteed to be loaded in yet at map spawn, so it's best to wait at least a frame for everything to load in.
:<code>yaw</code> - Unused?
+
 
:<code>dist</code> - Unused?
+
'''Warning:''' The function assumes that self is the current entity trying to snap to the floor.  
====Returns:====
+
 
:Returns  TRUE if the entity landed on the ground and FALSE if it was still in the air.
+
=== Return ===
====Other Details:====
+
Returns <code>TRUE</code> if the entity was placed on valid ground.
Note the 256 unit limitation. Typically droptofloor is either to pre-place items and monsters on the ground after a map has loaded but if an entity is  over 256 units from the ground, droptofloor will return false.
+
 
 +
== Example ==
 +
  // This function tries to keep an entity stuck to the ground
 +
float MoveToGround(vector pos)
 +
{
 +
    vector curOrigin = self.origin;
 +
    setorigin(self, pos);
 +
    if (!droptofloor())
 +
    {
 +
        setorigin(self, curOrigin);
 +
        return FALSE;
 +
    }
 +
 +
    return TRUE;
 +
}
  
 
[[Category:QuakeC Function]]
 
[[Category:QuakeC Function]]

Latest revision as of 12:13, 1 August 2023

float droptofloor()

Usage[edit]

Tries to move an entity to the nearest floor beneath it, up to 256 map units. This is mostly for snapping item and monsters to the ground at map start, but this function shouldn't be called within the initializer functions themselves. Not all entities are guaranteed to be loaded in yet at map spawn, so it's best to wait at least a frame for everything to load in.

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

Return[edit]

Returns TRUE if the entity was placed on valid ground.

Example[edit]

// This function tries to keep an entity stuck to the ground
float MoveToGround(vector pos)
{
    vector curOrigin = self.origin;
    setorigin(self, pos);
    if (!droptofloor())
    {
        setorigin(self, curOrigin);
        return FALSE;
    }

    return TRUE;
}