Sana Ursina motoruyla stringlengths 1 1.28k ⌀ | 3. şahıs kameradan kontrol edilen stringlengths 1 280 ⌀ | tekerlekleri dönen stringclasses 557
values | drift atabilen bir araba yapacağım. Tek dosya stringclasses 312
values | adım adım ekleyeceksin stringclasses 141
values | sonunda çalışacak. stringclasses 62
values |
|---|---|---|---|---|---|
## Adım 0: Kurulum | null | null | null | null | null |
```bash | null | null | null | null | null |
pip install ursina | null | null | null | null | null |
``` | null | null | null | null | null |
Ursina | Panda3D motorunun üstüne kurulmuş bir Python oyun motoru (Panda3D otomatik gelir). Python **3.10 - 3.12** arası en sorunsuz çalışır. Bir de `car.py` diye dosya oluştur | aşağıdaki adımları sırayla yapıştır. | null | null | null |
Sana Ursina motoruyla | 3. şahıs kameradan kontrol edilen | tekerlekleri dönen | drift atabilen bir araba yapacağım. Tek dosya | adım adım ekleyeceksin | sonunda çalışacak. |
## Adım 0: Kurulum | null | null | null | null | null |
```bash | null | null | null | null | null |
pip install ursina | null | null | null | null | null |
``` | null | null | null | null | null |
Ursina | Panda3D motorunun üstüne kurulmuş bir Python oyun motoru (Panda3D otomatik gelir). Python **3.10 - 3.12** arası en sorunsuz çalışır. Bir de `car.py` diye dosya oluştur | aşağıdaki adımları sırayla yapıştır. | null | null | null |
## Adım 1: Ursina Component Mantığı (önce kafana yerleştir) | null | null | null | null | null |
Ursina'da **her şey bir Entity'dir** ve parçalar birleşerek obje oluşturur: | null | null | null | null | null |
| Component | Görevi | | null | null | null | null | null |
|---|---| | null | null | null | null | null |
| `Entity` | Tüm nesnelerin kökü: pozisyon | rotasyon | scale taşır | | null | null | null |
| `model` | Görsel şekli ('cube' | 'sphere' | 'cylinder' veya özel mesh) | | null | null | null |
| `texture` / `color` | Yüzey görünümü | | null | null | null | null | null |
| `collider` | Çarpışma kutusu ('box' | 'sphere') | | null | null | null | null |
| `parent` | Parent-child hiyerarşisi (scene graph) → arabanın tekerleği arabayla hareket eder | | null | null | null | null | null |
| `update()` | Her kare (frame) çalışan fonksiyon → fizik burada | | null | null | null | null | null |
| `input()` | Tuş olayları | | null | null | null | null | null |
| `camera` | Sahneyi bakan göz | o da bir Entity | | null | null | null | null |
| `Text` | Ekran üstü yazı (HUD) | | null | null | null | null | null |
En önemli fikir: **parent-child**. Arabayı bir Entity | tekerleği onun child'ı yaparsın; araba hareket edince tekerlek de onunla gider. Direksiyon için ayrı bir pivot (dönüş ekseni) entity'si kullanacağız. | null | null | null | null |
## Adım 2: İskelet + Gökyüzü + Zemin | null | null | null | null | null |
```python | null | null | null | null | null |
from ursina import * | null | null | null | null | null |
import random | null | null | null | null | null |
import math | null | null | null | null | null |
app = Ursina() | null | null | null | null | null |
window.title = 'PyCar 3D' | null | null | null | null | null |
window.color = color.rgb(150 | 190 | 240) | null | null | null |
# Sis: uzak nesneler gökyüzü rengine karışır | derinlik hissi verir | null | null | null | null |
scene.fog_color = window.color | null | null | null | null | null |
scene.fog_density = 0.012 | null | null | null | null | null |
# Zemin: düzlem + çim dokusu | texture_scale ile doku tekrarlanır | null | null | null | null |
ground = Entity(model='plane' | scale=120 | texture='grass' | null | null | null |
texture_scale=(60 | 60) | color=color.rgb(140 | 200 | 120)) | null |
Sky() # gökyüzü küresi | null | null | null | null | null |
sun = Entity(model='sphere' | scale=8 | position=(60 | 40 | 80) | null |
color=color.rgb(255 | 235 | 140)) | null | null | null |
``` | null | null | null | null | null |
## Adım 3: Yol ve Şehir Dekoru | null | null | null | null | null |
```python | null | null | null | null | null |
# Asfalt | null | null | null | null | null |
road = Entity(model='cube' | scale=(7 | 0.1 | 120) | y=0.01 | color=color.rgb(60 |
# Orta şerit çizgileri (kesikli) | null | null | null | null | null |
for i in range(-14 | 15): | null | null | null | null |
if i % 2 == 0: | null | null | null | null | null |
Entity(model='cube' | scale=(0.15 | 0.11 | 2) | y=0.02 | null |
color=color.white | position=(0 | 0.02 | i * 4)) | null | null |
# Kenar çizgileri | null | null | null | null | null |
for x in (-3.3 | 3.3): | null | null | null | null |
Entity(model='cube' | scale=(0.12 | 0.11 | 120) | y=0.02 | null |
color=color.white | position=(x | 0.02 | 0)) | null | null |
# Binalar: rastgele yükseklik ve renk | brick dokusu | null | null | null | null |
for i in range(8): | null | null | null | null | null |
x = random.choice((-11 | -8.5 | 8.5 | 11)) | null | null |
z = random.uniform(-50 | 50) | null | null | null | null |
h = random.uniform(3 | 9) | null | null | null | null |
Entity(model='cube' | scale=(3 | h | 3) | position=(x | h/2 |
texture='brick' | texture_scale=(3 | int(h)) | null | null | null |
color=color.rgb(random.randint(140 | 230) | random.randint(140 | 230) | random.randint(140 | 230))) |
# Ağaçlar: silindir gövde + üst üste küpler (low-poly stil) | null | null | null | null | null |
for i in range(25): | null | null | null | null | null |
x = random.choice((-1 | 1)) * random.uniform(9 | 45) | null | null | null |
z = random.uniform(-55 | 55) | null | null | null | null |
Entity(model='cube' | scale=(0.3 | 1.4 | 0.3) | color=color.rgb(100 | 70 |
Entity(model='cube' | scale=1.1 | color=color.rgb(60 | 170 | 70) | position=(x |
rotation_y=random.uniform(0 | 45)) | null | null | null | null |
# Uzak tepeler: yarısı zeminin altına gömülü dev küreler | null | null | null | null | null |
for pos | s in [((-70 | -4 | -60) | (28 | 14 |
Entity(model='sphere' | scale=s | position=pos | color=color.rgb(105 | 125 | 95)) |
# Yolda engeller (çarpışma kutusuyla!) | null | null | null | null | null |
obstacles = [] | null | null | null | null | null |
for z in (-25 | -8 | 8 | 25): | null | null |
for x in (-2.4 | 2.4): | null | null | null | null |
ob = Entity(model='cube' | scale=1 | y=0.5 | position=(x | 0.5 | z) |
texture='white_cube' | color=color.rgb(255 | 140 | 0) | collider='box') | null |
obstacles.append(ob) | null | null | null | null | null |
``` | null | null | null | null | null |
## Adım 3.5: macOS Uyumlu Özel Silindir Mesh | null | null | null | null | null |
macOS'ta Ursina'nın `cylinder` modeli bazen OpenGL sürücü farklılıkları yüzünden bozulabiliyor. Tekerlekler için kendi procedural silindir mesh'imizi yazacağız. Bu hem macOS'ta hem Windows'ta %100 aynı çalışır: | null | null | null | null | null |
```python | null | null | null | null | null |
def make_wheel_mesh(radius=0.5 | thickness=0.3 | segments=10): | null | null | null |
"""Düşük poligonlu | tüm platformlarda çalışan tekerlek mesh'i""" | null | null | null | null |
verts = [] | null | null | null | null | null |
tris = [] | null | null | null | null | null |
half_t = thickness / 2 | null | null | null | null | null |
null | null | null | null | null | null |
# Sol yüzey (z = -half_t) | null | null | null | null | null |
for i in range(segments): | null | null | null | null | null |
angle = 2 * math.pi * i / segments | null | null | null | null | null |
x = math.cos(angle) * radius | null | null | null | null | null |
y = math.sin(angle) * radius | null | null | null | null | null |
verts.append(Vec3(x | y | -half_t)) | null | null | null |
null | null | null | null | null | null |
# Sağ yüzey (z = +half_t) | null | null | null | null | null |
for i in range(segments): | null | null | null | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.