diff --git a/Assets/Materials/WallMat.physicMaterial b/Assets/Materials/WallMat.physicMaterial new file mode 100644 index 0000000..786994d --- /dev/null +++ b/Assets/Materials/WallMat.physicMaterial @@ -0,0 +1,14 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!134 &13400000 +PhysicMaterial: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: WallMat + dynamicFriction: 0 + staticFriction: 0 + bounciness: 1 + frictionCombine: 1 + bounceCombine: 1 diff --git a/Assets/Materials/WallMat.physicMaterial.meta b/Assets/Materials/WallMat.physicMaterial.meta new file mode 100644 index 0000000..2c2e5b4 --- /dev/null +++ b/Assets/Materials/WallMat.physicMaterial.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: db65845c02126636d9fae11e1ea2f004 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 13400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Projectiles/Bullet.prefab b/Assets/Prefabs/Projectiles/Bullet.prefab index a1c57b3..80df278 100644 --- a/Assets/Prefabs/Projectiles/Bullet.prefab +++ b/Assets/Prefabs/Projectiles/Bullet.prefab @@ -146,6 +146,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a98521a4b559621438fc196adc605f3b, type: 3} m_Name: m_EditorClassIdentifier: - bounciness: 0.516 + bounciness: 1 damage: 10 wallRebounces: 4 + comingFrom: {fileID: 0} diff --git a/Assets/Scenes/TowerTest.unity b/Assets/Scenes/TowerTest.unity index 1520f0f..6db570d 100644 --- a/Assets/Scenes/TowerTest.unity +++ b/Assets/Scenes/TowerTest.unity @@ -335,7 +335,7 @@ BoxCollider: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 643774939} - m_Material: {fileID: 0} + m_Material: {fileID: 13400000, guid: db65845c02126636d9fae11e1ea2f004, type: 2} m_IncludeLayers: serializedVersion: 2 m_Bits: 0 @@ -440,7 +440,7 @@ BoxCollider: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 769011490} - m_Material: {fileID: 0} + m_Material: {fileID: 13400000, guid: db65845c02126636d9fae11e1ea2f004, type: 2} m_IncludeLayers: serializedVersion: 2 m_Bits: 0 @@ -745,7 +745,7 @@ BoxCollider: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1085503232} - m_Material: {fileID: 0} + m_Material: {fileID: 13400000, guid: db65845c02126636d9fae11e1ea2f004, type: 2} m_IncludeLayers: serializedVersion: 2 m_Bits: 0 @@ -850,7 +850,7 @@ BoxCollider: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1197417724} - m_Material: {fileID: 0} + m_Material: {fileID: 13400000, guid: db65845c02126636d9fae11e1ea2f004, type: 2} m_IncludeLayers: serializedVersion: 2 m_Bits: 0 @@ -955,7 +955,7 @@ BoxCollider: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1621186629} - m_Material: {fileID: 0} + m_Material: {fileID: 13400000, guid: db65845c02126636d9fae11e1ea2f004, type: 2} m_IncludeLayers: serializedVersion: 2 m_Bits: 0 @@ -1243,7 +1243,7 @@ PrefabInstance: - target: {fileID: 7348612162646443967, guid: fd9f9b61c0ebb324ebc9f929e26706bc, type: 3} propertyPath: m_LocalRotation.w - value: -0.13805284 + value: -0.1380528 objectReference: {fileID: 0} - target: {fileID: 7348612162646443967, guid: fd9f9b61c0ebb324ebc9f929e26706bc, type: 3} @@ -1258,7 +1258,7 @@ PrefabInstance: - target: {fileID: 7348612162646443967, guid: fd9f9b61c0ebb324ebc9f929e26706bc, type: 3} propertyPath: m_LocalRotation.z - value: -0.13815573 + value: -0.13815574 objectReference: {fileID: 0} - target: {fileID: 8882344377078016156, guid: fd9f9b61c0ebb324ebc9f929e26706bc, type: 3} @@ -1341,7 +1341,7 @@ BoxCollider: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1797347348} - m_Material: {fileID: 0} + m_Material: {fileID: 13400000, guid: db65845c02126636d9fae11e1ea2f004, type: 2} m_IncludeLayers: serializedVersion: 2 m_Bits: 0 diff --git a/Assets/Scripts/Tower/Projectile.cs b/Assets/Scripts/Tower/Projectile.cs index ea9a131..a947a32 100644 --- a/Assets/Scripts/Tower/Projectile.cs +++ b/Assets/Scripts/Tower/Projectile.cs @@ -8,6 +8,7 @@ public class Projectile : MonoBehaviour private float bounciness = 0.5f; private Collider projCol; + private Rigidbody body; [SerializeField, Range(0, 50)] private int damage = 10; @@ -15,20 +16,32 @@ public class Projectile : MonoBehaviour [SerializeField] private int wallRebounces = 4; private int hitWalls = 0; - + public HealthComponent comingFrom; + private Vector3 prevVel; + private void Awake() { projCol = GetComponent(); + body = GetComponent(); Assert.IsNotNull(projCol); PhysicMaterial pMat = new(); pMat.bounciness = this.bounciness; + pMat.staticFriction = 0f; + pMat.dynamicFriction = 0f; + pMat.frictionCombine = PhysicMaterialCombine.Minimum; + pMat.bounceCombine = PhysicMaterialCombine.Minimum; projCol.material = pMat; } + private void LateUpdate() + { + prevVel = body.velocity; + } + private void OnCollisionEnter(Collision collision) { HealthComponent hitHealthComp = collision.gameObject.GetComponent(); @@ -44,6 +57,8 @@ public class Projectile : MonoBehaviour { Destroy(gameObject); } + Vector3 newVel = Vector3.Reflect(prevVel.normalized, collision.contacts[0].normal.normalized); + body.velocity = newVel.normalized * prevVel.magnitude * bounciness; } } }