Commit 614160d0 authored by Martin Mihálik's avatar Martin Mihálik 🔥
Browse files

Rubble

parent 9ac6c231
......@@ -457,10 +457,10 @@ TextureImporter:
name: spritesheet_explosive_9
rect:
serializedVersion: 2
x: 780
x: 781
y: 767
width: 56
height: 61
width: 55
height: 60
alignment: 0
pivot: {x: 0.5, y: 0.5}
border: {x: 0, y: 0, z: 0, w: 0}
......
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!62 &6200000
PhysicsMaterial2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Ground
friction: 1
bounciness: 0
fileFormatVersion: 2
guid: 9585bd1897407494d9d3063e1a79010f
guid: 0af07f9debd10a04cbda18bd1aeb291a
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 6200000
......
......@@ -6,6 +6,6 @@ PhysicsMaterial2D:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: NoFriction
m_Name: Player
friction: 0
bounciness: 0
fileFormatVersion: 2
guid: 89d55aeb787742242b2cc5b64b8ba11a
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 6200000
userData:
assetBundleName:
assetBundleVariant:
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!62 &6200000
PhysicsMaterial2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Rubble
friction: 1
bounciness: 0
fileFormatVersion: 2
guid: 2ffe6e0f2c9969e4a9775889185ac650
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 6200000
userData:
assetBundleName:
assetBundleVariant:
......@@ -13,7 +13,7 @@ GameObject:
- component: {fileID: 82881188109033697}
- component: {fileID: 82881188109033699}
- component: {fileID: 82881188109033698}
m_Layer: 0
m_Layer: 9
m_Name: Meteor
m_TagString: Untagged
m_Icon: {fileID: 0}
......@@ -136,6 +136,7 @@ MonoBehaviour:
m_Direction: {x: 0, y: 0}
m_Speed: 0
m_ExplosionPrefab: {fileID: 9034781248440383852, guid: c84a1d0620e6bee4099ba5078530b2bc, type: 3}
m_RubblePrefab: {fileID: 4362927315812235910, guid: b70e9174981d32c40861eb95d6d1b357, type: 3}
--- !u!96 &82881188109033698
TrailRenderer:
serializedVersion: 2
......
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &4362927315812235910
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4362927315812235906}
- component: {fileID: 4362927315812235907}
- component: {fileID: 4362927315812235908}
- component: {fileID: 4362927315812235909}
m_Layer: 6
m_Name: Rubble
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4362927315812235906
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4362927315812235910}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4362927315981378692}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &4362927315812235907
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4362927315812235910}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 3866238095531631272, guid: 5c50de58f500a2644b5025c5b9bb9e40, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 0.56, y: 0.61}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!60 &4362927315812235908
PolygonCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4362927315812235910}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 0.55, y: 0.6}
newSize: {x: 0.56, y: 0.61}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
m_Points:
m_Paths:
- - {x: 0.11090686, y: 0.29930896}
- {x: 0.09522903, y: 0.30152303}
- {x: 0.04129324, y: 0.3067385}
- {x: -0.26662138, y: -0.12096037}
- {x: -0.27130756, y: -0.18800151}
- {x: -0.24349207, y: -0.22283064}
- {x: 0.10952442, y: -0.31195387}
- {x: 0.15826176, y: -0.2945692}
- {x: 0.2843091, y: -0.013796428}
- {x: 0.278216, y: 0.016365893}
--- !u!50 &4362927315812235909
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4362927315812235910}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 1
m_Material: {fileID: 6200000, guid: 2ffe6e0f2c9969e4a9775889185ac650, type: 2}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 0
--- !u!1 &4362927315981378693
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4362927315981378692}
- component: {fileID: 4362927315981378691}
- component: {fileID: 4362927315981378690}
m_Layer: 8
m_Name: Collectible
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4362927315981378692
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4362927315981378693}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4362927315812235906}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!58 &4362927315981378691
CircleCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4362927315981378693}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 1
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0.05, y: 0}
serializedVersion: 2
m_Radius: 0.15
--- !u!114 &4362927315981378690
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4362927315981378693}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 610be74bcb2e1de4395cf0c601fe712d, type: 3}
m_Name:
m_EditorClassIdentifier:
fileFormatVersion: 2
guid: b70e9174981d32c40861eb95d6d1b357
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -137,7 +137,7 @@ GameObject:
- component: {fileID: 512397501}
- component: {fileID: 512397505}
- component: {fileID: 512397506}
m_Layer: 0
m_Layer: 7
m_Name: Player
m_TagString: Untagged
m_Icon: {fileID: 0}
......@@ -160,7 +160,7 @@ Rigidbody2D:
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 3
m_Material: {fileID: 0}
m_Material: {fileID: 6200000, guid: 89d55aeb787742242b2cc5b64b8ba11a, type: 2}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
......@@ -174,7 +174,7 @@ BoxCollider2D:
m_GameObject: {fileID: 512397500}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 6200000, guid: 9585bd1897407494d9d3063e1a79010f, type: 2}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
......@@ -309,7 +309,7 @@ GameObject:
- component: {fileID: 519420032}
- component: {fileID: 519420031}
- component: {fileID: 519420029}
m_Layer: 0
m_Layer: 7
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
......@@ -1130,7 +1130,7 @@ Rigidbody2D:
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 1
m_Material: {fileID: 0}
m_Material: {fileID: 6200000, guid: 0af07f9debd10a04cbda18bd1aeb291a, type: 2}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
......
......@@ -5,39 +5,66 @@ public class MeteorController : MonoBehaviour
public Vector2 m_Direction = Vector2.zero;
public float m_Speed = 0f;
private bool m_Move = true;
[SerializeField] private GameObject m_ExplosionPrefab;
[SerializeField] private GameObject m_RubblePrefab;
private float RotationSpeed {
get => 360f;
}
private Transform m_Meteor;
private SpriteRenderer m_Sprite;
private Collider2D m_Collider;
private void Start()
{
m_Meteor = GetComponent<Transform>();
m_Sprite = GetComponent<SpriteRenderer>();
m_Collider = GetComponent<Collider2D>();
m_Direction.Normalize();
}
private void FixedUpdate()
private void Move()
{
if (m_Move)
{
Vector3 movement = m_Direction;
m_Meteor.position += movement * m_Speed * Time.fixedDeltaTime;
Vector3 movement = m_Direction * m_Speed * Time.fixedDeltaTime;
m_Meteor.Rotate(Vector3.forward * RotationSpeed * Time.fixedDeltaTime);
}
gameObject.transform.position += movement;
}
private void Rotate()
{
gameObject.transform.Rotate(Vector3.forward * 360f * Time.fixedDeltaTime);
}
private void FixedUpdate()
{
Move();
Rotate();
}
public void OnTriggerEnter2D(Collider2D other)
{
m_Move = false;
Crash();
}
private void Crash()
{
Stop();
Explode();
}
private void Stop()
{
m_Speed = 0f;
}
private void Explode()
{
Disappear();
SpawnExplosion(m_Meteor.position, 2, 4, m_Meteor.parent);
SpawnExplosion(gameObject.transform.position, 2f, 4f, gameObject.transform.parent);
SpawnRubble(3, gameObject.transform.position, 200f, gameObject.transform.parent);
}
private void Disappear()
{
m_Sprite.enabled = false;
m_Collider.enabled = false;
}
private void SpawnExplosion(Vector2 position, float maxScale, float growthRate, Transform parent)
......@@ -49,4 +76,25 @@ public class MeteorController : MonoBehaviour
controller.m_MaxScale = maxScale;
controller.m_GrowthRate = growthRate;
}
private void SpawnRubble(uint count, Vector2 basePosition, float force, Transform parent)
{
for (uint i = 0; i < count; ++i)
{
var offset = new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f));
var startingPoint = basePosition + offset;
SpawnSingleRubble(startingPoint, (startingPoint - basePosition).normalized, force, parent);
}
}
private void SpawnSingleRubble(Vector2 startingPosition, Vector2 direction, float force, Transform parent)
{
var rubble = Instantiate(m_RubblePrefab, startingPosition, Quaternion.identity, parent);
var rubbleBody = rubble.GetComponent<Rigidbody2D>();
rubbleBody.AddForce(direction * force);
}
}
......@@ -7,6 +7,7 @@ PhysicsManager:
m_Gravity: {x: 0, y: -9.81, z: 0}
m_DefaultMaterial: {fileID: 0}
m_BounceThreshold: 2
m_DefaultMaxDepenetrationVelocity: 10
m_SleepThreshold: 0.005
m_DefaultContactOffset: 0.01
m_DefaultSolverIterations: 6
......
......@@ -53,4 +53,4 @@ Physics2DSettings:
m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432}
m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745}
m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804}
m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffff7ffdffffbffffffffffdffffbffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
......@@ -11,10 +11,10 @@ TagManager:
- Ground
- Water
- UI
-
-
-
-
- Rubble
- Player
- Collectible
- Meteor
-
-
-
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment