Start Unity
375 subscribers
7 photos
1 video
11 links
هیچ پروسه ای سخت نیست به شرطی که شروعش کنی..

🎮 #یونیتی
👨‍💻 #برنامه_نویسی
📚 #آموزش
🧩 #آزمون

گروه: @StartUnityGP

🫂 @AmirHDeveloper @HaminGames
Download Telegram
Channel created
.
👌5🔥4👍2🙏2
Start Unity
#نکات_مهم
از اینا 4 تا دونشو عادت دارم خودم🤦‍♂️😂😂
Channel photo updated
برخی از متدهای کلاس‌های Vector2 و Vector3 همراه با نمونه کد:

### Vector2:

1. `Distance(Vector2 a, Vector2 b)`:
- توضیح: این متد فاصله‌ی اقلیدسی (Euclidean distance) بین دو نقطه‌ی مشخص را محاسبه می‌کند.
- نمونه کد:

     Vector2 pointA = new Vector2(1.0f, 2.0f);
Vector2 pointB = new Vector2(4.0f, 6.0f);

float distance = Vector2.Distance(pointA, pointB);


2. `Dot(Vector2 lhs, Vector2 rhs)`:
- توضیح: این متد محصول نقطه‌ای (dot product) دو بردار را محاسبه می‌کند.
- نمونه کد:

     Vector2 vectorA = new Vector2(2.0f, 3.0f);
Vector2 vectorB = new Vector2(1.0f, 2.0f);

float dotProduct = Vector2.Dot(vectorA, vectorB);


### Vector3:

1. `Angle(Vector3 from, Vector3 to)`:
- توضیح: این متد زاویه‌ی بین دو بردار را با استفاده از محصول نقطه‌ای محاسبه می‌کند.
- نمونه کد:

     Vector3 fromVector = new Vector3(1.0f, 0.0f, 0.0f);
Vector3 toVector = new Vector3(0.0f, 1.0f, 0.0f);

float angle = Vector3.Angle(fromVector, toVector);


2. `Reflect(Vector3 inDirection, Vector3 inNormal)`:
- توضیح: این متد بازتاب بردار وارون شده از یک سطح را محاسبه می‌کند.
- نمونه کد:

     Vector3 incident = new Vector3(1.0f, -1.0f, 0.0f).normalized;
Vector3 normal = new Vector3(0.0f, 1.0f, 0.0f).normalized;

Vector3 reflected = Vector3.Reflect(incident, normal);


3. `Project(Vector3 vector, Vector3 onNormal)`:
- توضیح: این متد پروژکشن یک بردار بر روی یک بردار دیگر را محاسبه می‌کند.
- نمونه کد:

     Vector3 vectorToProject = new Vector3(3.0f, 4.0f, 5.0f);
Vector3 ontoVector = new Vector3(1.0f, 0.0f, 0.0f);

Vector3 projectedVector = Vector3.Project(vectorToProject, ontoVector);


4. `Lerp(Vector3 a, Vector3 b, float t)`:
- توضیح: این متد یک بردار در طول یک مسیر خطی بین دو بردار مبدأ و مقصد ایجاد می‌کند.
- نمونه کد:

     Vector3 vectorA = new Vector3(1.0f, 2.0f, 3.0f);
Vector3 vectorB = new Vector3(4.0f, 5.0f, 6.0f);

Vector3 lerpedVector = Vector3.Lerp(vectorA, vectorB, 0.5f);


5. `Slerp(Vector3 a, Vector3 b, float t

)`:

- توضیح: این متد یک بردار در طول یک مسیر قطبی بین دو بردار مبدأ و مقصد ایجاد می‌کند.
- نمونه کد:

     Vector3 vectorA = new Vector3(1.0f, 0.0f, 0.0f);
Vector3 vectorB = new Vector3(0.0f, 1.0f, 0.0f);

Vector3 slerpedVector = Vector3.Slerp(vectorA, vectorB, 0.5f);


6. `RotateTowards(Vector3 current, Vector3 target, float maxRadiansDelta, float maxMagnitudeDelta)`:
- توضیح: این متد یک بردار را به سمت یک بردار هدف چرخانده و محدودیت‌هایی برای حرکت را اعمال می‌کند.
- نمونه کد:

     Vector3 currentVector = new Vector3(1.0f, 0.0f, 0.0f);
Vector3 targetVector = new Vector3(0.0f, 1.0f, 0.0f);

float maxRadiansDelta = 0.1f;
float maxMagnitudeDelta = 0.01f;

Vector3 rotatedVector = Vector3.RotateTowards(currentVector, targetVector, maxRadiansDelta, maxMagnitudeDelta);


7. `MoveTowards(Vector3 current, Vector3 target, float maxDistanceDelta)`:
- توضیح: این متد یک بردار را به سمت یک بردار هدف حرکت می‌دهد با محدودیت فاصله حداکثری.
- نمونه کد:

     Vector3 currentVector = new Vector3(1.0f, 0.0f, 0.0f);
Vector3 targetVector = new Vector3(0.0f, 1.0f, 0.0f);

float maxDistanceDelta = 0.1f;

Vector3 movedVector = Vector3.MoveTowards(currentVector, targetVector, maxDistanceDelta);


8. `SmoothDamp(Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime, float maxSpeed)`:
- توضیح: این متد یک بردار را به سمت یک بردار هدف با استفاده از حرکت انسیابی (Smooth Damping) حرکت می‌دهد.
- نمونه کد:

     Vector3 currentVector = new Vector3(1.0f, 0.0f, 0.0f);
Vector3 targetVector = new Vector3(0.0f, 1.0f, 0.0f);
Vector3 currentVelocity = Vector3.zero;
float smoothTime = 0.5f;
float maxSpeed = 2.0f;

Vector3 smoothedVector = Vector3.SmoothDamp(currentVector, targetVector, ref currentVelocity, smoothTime, maxSpeed);


#یونیتی #برنامه_نویسی
🔥5