Skip to content

Commit

Permalink
Ia do dragão melhorada
Browse files Browse the repository at this point in the history
  • Loading branch information
KSalmaze committed Oct 4, 2024
1 parent dde49c3 commit 528f4ad
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 12 deletions.
42 changes: 36 additions & 6 deletions Assets/Scenes/Stages/3.unity
Original file line number Diff line number Diff line change
Expand Up @@ -2192,6 +2192,7 @@ GameObject:
- component: {fileID: 761357772}
- component: {fileID: 761357771}
- component: {fileID: 761357770}
- component: {fileID: 761357775}
m_Layer: 0
m_Name: Cube
m_TagString: Untagged
Expand All @@ -2213,23 +2214,25 @@ MonoBehaviour:
m_EditorClassIdentifier:
attackCooldown: 4
rotationSpeed: 16
playerLayer:
serializedVersion: 2
m_Bits: 512
rb: {fileID: 761357775}
meleeAttackPoint: {fileID: 1576578434}
meleeDamage: 4
meleeRange: 8
meleeForce: 0
jumpDamage: 6
jumpRange: 15
jumpDamageRange: 20
behindAngleThreshold: 120
shockwave: {fileID: 2102854067}
_shockwave: {fileID: 2102854074}
shockwaveForce: 0
shockwaveMaxHeight: 0
shockwaveSpeed: 0
jumpDuration: 10
jumpHeight: 15
breathingPoint: {fileID: 861041994}
fireBreathAngle: 61.9
fireBreathDuration: 2
range: 31.2
damage: 0
damage: 1
fireBreathEffect: {fileID: 0}
--- !u!65 &761357771
BoxCollider:
Expand Down Expand Up @@ -2321,6 +2324,33 @@ Transform:
- {fileID: 1581534160}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: -115.03, z: 0}
--- !u!54 &761357775
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 761357769}
serializedVersion: 4
m_Mass: 1
m_Drag: 0
m_AngularDrag: 0.05
m_CenterOfMass: {x: 0, y: 0, z: 0}
m_InertiaTensor: {x: 1, y: 1, z: 1}
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_ImplicitCom: 1
m_ImplicitTensor: 1
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!1 &861041993
GameObject:
m_ObjectHideFlags: 0
Expand Down
58 changes: 55 additions & 3 deletions Assets/Scripts/AI/Dragon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public class Dragon : MonoBehaviour
[Header("General")]
[SerializeField] private float attackCooldown;
[SerializeField] private float rotationSpeed;
[SerializeField] private LayerMask playerLayer;
[SerializeField] private Rigidbody rb;

[Header("Melee attack")]
[SerializeField] private Transform meleeAttackPoint;
Expand All @@ -16,12 +18,15 @@ public class Dragon : MonoBehaviour
[Header("Jump attack")]
[SerializeField] private int jumpDamage;
[SerializeField] private float jumpRange;
[SerializeField] private float jumpDamageRange = 20f;
[SerializeField] private float behindAngleThreshold = 200f;
[SerializeField] private GameObject shockwave;
[SerializeField] private float jumpDuration = 10f;
[SerializeField] private float jumpHeight = 15f;
/*[SerializeField] private GameObject shockwave;
[SerializeField] private Shockwave _shockwave;
[SerializeField] private float shockwaveForce;
[SerializeField] private float shockwaveMaxHeight;
[SerializeField] private float shockwaveSpeed;
[SerializeField] private float shockwaveSpeed;*/

[Header("Fire Breath")]
[SerializeField] private Transform breathingPoint;
Expand All @@ -34,6 +39,7 @@ public class Dragon : MonoBehaviour
private Transform _playerTransform;
private float _distanceToPlayer;
private HPController _playerHealth;
private Vector3 _targetPosition;

// Start is called before the first frame update
void Start()
Expand Down Expand Up @@ -131,7 +137,53 @@ void JumpAttack()
{
Debug.Log("Jump Attack");

_shockwave.StartRising();
StartCoroutine(JumpAttackCoroutine());
}

IEnumerator JumpAttackCoroutine()
{
// Fase de salto
yield return StartCoroutine(PerformJump());

// Fase de queda e impacto
yield return StartCoroutine(PerformLanding());
}

IEnumerator PerformJump()
{
Vector3 startPosition = transform.position;
_targetPosition = _playerTransform.position;

float elapsedTime = 0f;

while (elapsedTime < jumpDuration)
{
float t = elapsedTime / jumpDuration;
float height = Mathf.Sin(t * Mathf.PI) * jumpHeight;

transform.position = Vector3.Lerp(startPosition, _targetPosition, t) + Vector3.up * height;

elapsedTime += Time.deltaTime;
yield return null;
}
}

IEnumerator PerformLanding()
{
transform.position = _targetPosition;

// Efeito de impacto
rb.AddForce(Vector3.down * 10f, ForceMode.Impulse);

// Verifica se o jogador está na área de impacto
Collider[] hitColliders = Physics.OverlapSphere(transform.position, jumpDamageRange, playerLayer);
foreach (var hitCollider in hitColliders)
{
_playerHealth.LoseHP(jumpDamage);
}

Debug.Log("Ataque de pulo concluído");
yield return null;
}

void FireBreathAttack()
Expand Down
11 changes: 8 additions & 3 deletions ProjectSettings/Packages/com.unity.probuilder/Settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
{
"type": "UnityEngine.ProBuilder.SelectMode, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"key": "editor.lastMeshSelectMode",
"value": "{\"m_Value\":8}"
"value": "{\"m_Value\":2}"
},
{
"type": "UnityEngine.ProBuilder.SelectionModifierBehavior, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
Expand All @@ -119,7 +119,7 @@
{
"type": "System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"key": "ShapeBuilder.ActiveShapeIndex",
"value": "{\"m_Value\":6}"
"value": "{\"m_Value\":7}"
},
{
"type": "System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
Expand All @@ -139,7 +139,7 @@
{
"type": "UnityEngine.Vector3, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"key": "ShapeBuilder.LastSize",
"value": "{\"m_Value\":{\"x\":1.1713848114013672,\"y\":9.782410621643067,\"z\":-40.267616271972659}}"
"value": "{\"m_Value\":{\"x\":20.437580108642579,\"y\":33.69776153564453,\"z\":-22.726688385009767}}"
},
{
"type": "UnityEngine.Quaternion, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
Expand Down Expand Up @@ -181,6 +181,11 @@
"key": "ShapeBuilder.Cube",
"value": "{}"
},
{
"type": "UnityEngine.ProBuilder.Shapes.Shape, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"key": "ShapeBuilder.Cylinder",
"value": "{}"
},
{
"type": "System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"key": "uv.uvEditorGridSnapIncrement",
Expand Down

0 comments on commit 528f4ad

Please sign in to comment.