# util.IntersectRayWithSphere

- **Ortam:** İstemci, Sunucu
- **İngilizce aslı:** https://wiki.facepunch.com/gmod/util.IntersectRayWithSphere
- **Çeviri tarihi:** 2025-09-08

```lua
number, number util.IntersectRayWithSphere( Vector rayOrigin, Vector rayDelta, Vector spherePosition, number sphereRadius )
```

## Açıklama

Bir ışın-küre kesişimi gerçekleştirir ve kesişim pozisyonlarını veya nil değerini döndürür.

## Argümanlar

1. [Vector](https://gmod.tr/wiki/Vector) **rayOrigin**: Işının orijin/başlangıç pozisyonu.
2. [Vector](https://gmod.tr/wiki/Vector) **rayDelta**: Işının başlangıç pozisyonuna göre bitiş pozisyonu. `yön * mesafe` ifadesine eşdeğerdir.
3. [Vector](https://gmod.tr/wiki/Vector) **spherePosition**: Kürenin herhangi bir pozisyonu.
4. [number](https://gmod.tr/wiki/number) **sphereRadius**: Kürenin yarıçapı.

## Dönüşler

1. [number](https://gmod.tr/wiki/number): Işın boyunca ilk kesişim pozisyonu, eğer kesişim yoksa `nil`.
2. [number](https://gmod.tr/wiki/number): Işın boyunca ikinci kesişim pozisyonu, eğer kesişim yoksa `nil`.

### Örnek

```lua
-- Baktığımız entity'yi sakla
local ent = NULL

-- Bunu her karede yap
hook.Add( "Think", "Think_IntersectRayWithOBBExample", function()

	-- Oyuncu nesnesini sakla
	local ply = LocalPlayer()

	-- Eğer oyuncu geçerli bir entity'ye bakıyorsa, bizim entity'mizi onunla değiştir
	local trEnt = ply:GetEyeTrace().Entity
	if ( IsValid( trEnt ) ) then ent = trEnt end

	-- Entity yok mu? Hiçbir şey yapma
	if ( !IsValid( ent ) ) then return end

	local start = ply:GetShootPos()
	local delta = ply:GetAimVector() * 500
	local endpos = start + delta

	-- Oyuncunun gözlerinden bir küreye doğru ışın kesişimi gerçekleştir
	local frac1, frac2 = util.IntersectRayWithSphere( start, delta, ent:GetPos() + ent:OBBCenter(), ent:OBBMaxs():Length() )
	--print( "res: ", frac1, frac2 ) -- Hata ayıklama için

	-- Kesişim noktalarını göster
	if ( frac1 ) then
		local intersect1 = LerpVector( frac1, start, endpos )
		local intersect2 = LerpVector( frac2, start, endpos )
		debugoverlay.Axis( intersect1, angle_zero, 10, 0.01 )
		debugoverlay.Axis( intersect2, angle_zero, 10, 0.01 )
	end

	-- OBB görselleştirmesini çizer, konsolda developer 1 gerektirir.
	debugoverlay.Sphere( ent:GetPos() + ent:OBBCenter(), ent:OBBMaxs():Length(), 0.01, frac1 != nil and Color( 0, 255, 0 ) or Color( 255, 0, 0 ) )

end )
```

- [GMod Wiki ana sayfası](https://gmod.tr/wiki)

---

[Tüm sunucular](https://gmod.tr/) · [GmodTR Launcher](https://gmod.tr/launcher) · [Rehber](https://gmod.tr/rehber) · [GMod Wiki](https://gmod.tr/wiki) · [GmodTR nedir?](https://gmod.tr/hakkinda) · [Sunucu ekle](https://gmod.tr/sunucu-ekle) · [Discord](https://discord.gg/gmodtr)

Kaynak: https://gmod.tr/wiki/util.IntersectRayWithSphere
