This shows you the differences between two versions of the page.
pjv:laboratoare:2022:03 [2022/11/09 12:12] alexandru.gradinaru |
pjv:laboratoare:2022:03 [2022/11/10 15:05] (current) alexandru.gradinaru |
||
---|---|---|---|
Line 7: | Line 7: | ||
<note tip>Resurse folosite: | <note tip>Resurse folosite: | ||
* [[https://assetstore.unity.com/packages/3d/environments/fantasy/fantasy-forest-environment-free-demo-35361|Fantasy Forest Environment - Free Demo]] | * [[https://assetstore.unity.com/packages/3d/environments/fantasy/fantasy-forest-environment-free-demo-35361|Fantasy Forest Environment - Free Demo]] | ||
+ | * [[https://assetstore.unity.com/?category=3d%2Fenvironments%5C3d%2Fvegetation&free=true&orderBy=1|3D Environments - vegetatation]] | ||
+ | * [[https://assetstore.unity.com/packages/3d/environments/fantasy/canon-tower-50215|Canon tower]] | ||
+ | * [[https://assetstore.unity.com/packages/3d/environments/fantasy/awesome-stylized-mage-tower-53793|Canon tower 2]] | ||
+ | * [[https://assetstore.unity.com/packages/3d/environments/stylized-fantasy-house-153587|Fantasy house]] | ||
+ | * [[https://assetstore.unity.com/packages/3d/environments/fantasy/fantasy-kindom-building-pack-lite-78378|Fantasy kingdom]] | ||
+ | * [[https://assetstore.unity.com/packages/3d/environments/fantasy/baker-s-house-26443|Baker house]] | ||
</note> | </note> | ||
Line 13: | Line 19: | ||
* Mediul: | * Mediul: | ||
* un teren cu 3 lane-uri | * un teren cu 3 lane-uri | ||
- | * turnuri pe fiecare lane (vedeti punctele rosii/albastre de pe harta) | + | * turnuri pe fiecare lane (vedeti punctele rosii/albastre de pe harta) - ar trebui sa fie diferentiate pe echipe (de ex un steag de culoare deferita, sau o culoare de material deferita etc.) |
- | * cate o baza pentru fiecare player | + | * cate o baza pentru fiecare player (de ex un steag de culoare deferita, sau o culoare de material deferita etc.) |
{{ :pjv:laboratoare:2022:map_of_moba.svg.png |}} | {{ :pjv:laboratoare:2022:map_of_moba.svg.png |}} | ||
* Playerul are 2 moduri de control. Schimbul intre cele doua moduri se poate face folosind o tasta, sau la anumite evenimente definite de voi | * Playerul are 2 moduri de control. Schimbul intre cele doua moduri se poate face folosind o tasta, sau la anumite evenimente definite de voi | ||
Line 174: | Line 180: | ||
==== Agenti ==== | ==== Agenti ==== | ||
- | Pentru a programa inamici sau agenti NPC (Non-Playable Character) se poate folosi aceeasi functionalitate de navigare automata (NavMesh) si componenta de tip NavMeshAgent, pentru navigatie, similar cu sectiunea de Navigare automata din laboratorul precedent. | + | Pentru a programa o miscare automata pe harta se poate folosi aceasta functionalitate de navigare automata (NavMesh) si componenta de tip NavMeshAgent. |
- | Diferenta este ca acesti agenti vor raspunde automat la anumite evenimente: | ||
- | * inamicii de obicei incep sa interactioneze atunci cand player-ul intra intr-o anumita raza de actiune | ||
- | * NPC-urile interactoneaza la fel, bazate pe o raza de actiune sau efectiv interactiune directa (click) | ||
=== Inamici === | === Inamici === | ||
Line 227: | Line 230: | ||
</code> | </code> | ||
- | O problema in activitatea agentilor este detectarea player-ului, in sensul de referinta. Astfel, avem mai multe variante: | ||
- | * putem cauta un obiect dupa tag | ||
- | * intr-o variabila target putem referentia direct player-ul (dar asta inseamna ca la fiecare agent trebuie mapat) | ||
- | * putem folosi un singleton in care se tine referentiaza playerul si poate fi accesat de oriunde | ||
- | <code> | ||
- | public class PlayerManager : MonoBehaviour { | ||
- | |||
- | public static PlayerManager instance; | ||
- | public GameObject player; | ||
- | | ||
- | void Awake() | ||
- | { | ||
- | instance = this; | ||
- | } | ||
- | |||
- | } | ||
- | </code> | ||
- | |||
- | Folosind varianta simpla cu singleton, putem lua pozitia player-ului de inters, similar cu laboratorul precedent: | ||
- | |||
- | <code> | ||
- | target = PlayerManager.instance.player.transform; | ||
- | </code> | ||
- | |||
- | Astfel, putem efectua usor operatii care tin de player - de exemplu putem orienta inamicii sau un npc cu fata catre player, in momentul unei interactiuni. | ||
- | |||
- | <code> | ||
- | |||
- | //Roteste cu 90 grade | ||
- | void RotateN() { | ||
- | Vector3 currentRotation = transform.rotation; | ||
- | Vector3 wantedRotation = currentRotation * Quaternion.AngleAxis(-90, Vector3.up); | ||
- | transform.rotation = Quaternion.Slerp(currentRotation, wantedRotation, Time.deltaTime * rotationSpeed); | ||
- | } | ||
- | //Roteste inamicul cu fata catre player | ||
- | void FaceTarget () | ||
- | { | ||
- | Vector3 direction = (target.position - transform.position).normalized; | ||
- | Quaternion lookRotation = Quaternion.LookRotation(new Vector3(direction.x, 0, direction.z)); | ||
- | transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * 5f); | ||
- | } | ||
- | </code> | ||
=== Miscarea personajului la o destinatie point-and-click === | === Miscarea personajului la o destinatie point-and-click === |