Vec3Offset

From ZDoom Wiki
Jump to navigation Jump to search
Note: This feature is for ZScript only.


native clearscope vector3 Vec3Offset(double x, double y, double z[, bool absolute]) const

Usage

Calculates a 3D offset from the caller's current origin by the given amounts. This should be used over doing it manually since it is portal aware. Note that the values are not relative to the caller's current angle but are absolute. This function will not modify the calling Actor's position.

Parameters

  • x - The amount to offset by on the x axis
  • y - The amount to offset by on the y axis
  • z - The amount to offset by on the z axis
  • absolute - Default is false. If true, completely ignores portals.

Return value

Returns a Vector3 containing the new offset position.

Examples

This function will try to spawn a specified actor 128 units in front of the calling actor.

bool SpawnMonsterInFront(class<Actor> cls)
{
	// Get an offset of 128 units and rotate it
	// to match the calling actor's angle:
	Vector2 ofs = RotateVector((128, 0), self.angle); 
	// Add it to the actor's current position:
	Vector3 ppos = Vec3Offset(ofs.x, ofs.y, 0);
	if (!level.IsPointInLevel(ppos))
	{
		Console.Printf("Couldn't spawn in the void");
		return false;
	}
	let mo = Spawn(cls, ppos);
	if (mo && !mo.TestMobjLocation())
	{
		Console.Printf("Not enough space for %s", mo.GetTag());
		mo.Destroy();
		return false;
	}
	return true;
}

See also RotateVector, TestMobjLocation, IsPointInLevel.