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: | ||
− | + | ''float'' '''droptofloor'''() | |
− | |||
− | Tries to | + | == Usage == |
− | === | + | 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 === | |
− | == | + | Returns <code>TRUE</code> if the entity was placed on valid ground. |
− | + | ||
+ | == 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; }