Skip to content

Commit

Permalink
Repaired the knockback + set the ignore layers from the project settings
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaiAnghelin committed Jun 9, 2019
1 parent 31f80b4 commit b1ac1e4
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 97 deletions.
Binary file not shown.
Binary file removed Awkna/.vs/Awkna/v16/Server/sqlite3/storage.ide-wal
Binary file not shown.
4 changes: 4 additions & 0 deletions Awkna/Assets/Prefabs/Scene Objects/Player.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ MonoBehaviour:
swingForce: 4
switchGravityPower: 0
energyUI: {fileID: 0}
knockback: 5
knockbackLength: 0.2
knockbackCount: 0
knockFromRight: 0
--- !u!114 &2115697293848515369
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
1 change: 0 additions & 1 deletion Awkna/Assets/Prefabs/Scene Objects/PlayerStats.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,4 @@ MonoBehaviour:
gemNumber: 0
ropeMaxCastDistance: 5
invulnerabilityTime: 0.5
knockbackPwr: 3
level: 0
4 changes: 2 additions & 2 deletions Awkna/Assets/Prefabs/Scene Objects/U.I. Holder.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -4681,7 +4681,7 @@ PrefabInstance:
- target: {fileID: 2498314325623954127, guid: de5d22107f8396e42b8ad2de1fca791d,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 159
value: 200
objectReference: {fileID: 0}
- target: {fileID: 2498314325623954127, guid: de5d22107f8396e42b8ad2de1fca791d,
type: 3}
Expand All @@ -4691,7 +4691,7 @@ PrefabInstance:
- target: {fileID: 2498314325623954127, guid: de5d22107f8396e42b8ad2de1fca791d,
type: 3}
propertyPath: m_SizeDelta.x
value: 239.4
value: 371.2
objectReference: {fileID: 0}
- target: {fileID: 2498314325623954127, guid: de5d22107f8396e42b8ad2de1fca791d,
type: 3}
Expand Down
24 changes: 0 additions & 24 deletions Awkna/Assets/Prefabs/Tiles/ExplosiveBox.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ GameObject:
- component: {fileID: 3032946328403841246}
- component: {fileID: 646149728043497314}
- component: {fileID: -205999473003186166}
- component: {fileID: 8930437183429454944}
- component: {fileID: 1074660908635139586}
- component: {fileID: 5157700398643278258}
m_Layer: 17
Expand Down Expand Up @@ -123,29 +122,6 @@ Rigidbody2D:
m_SleepingMode: 1
m_CollisionDetection: 1
m_Constraints: 4
--- !u!114 &8930437183429454944
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2910687485101638016}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9646103a204b95d48810e4e7e3c78f03, type: 3}
m_Name:
m_EditorClassIdentifier:
areaOfEffect: 1.5
whatIsDestructible:
serializedVersion: 2
m_Bits: 37120
damagePlayer: 5
offset: {x: 0, y: -0.475}
size: {x: 0.94, y: 0.05}
effect: {fileID: 139366, guid: b185c1a9cf067374586d095111b15bd1, type: 3}
whatIsGround:
serializedVersion: 2
m_Bits: 17152
--- !u!61 &1074660908635139586
BoxCollider2D:
m_ObjectHideFlags: 0
Expand Down
2 changes: 1 addition & 1 deletion Awkna/Assets/Prefabs/Tiles/HorizontallLaser.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -5080,7 +5080,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 7e107acab6c37ca42b82ebec3ed1a3c3, type: 3}
m_Name:
m_EditorClassIdentifier:
damage: 0.05
damage: 1
offset: {x: -0.5, y: 0.14}
size: {x: 0.94, y: 0.2}
--- !u!61 &5788405329986973560
Expand Down
2 changes: 1 addition & 1 deletion Awkna/Assets/Prefabs/Tiles/Kill.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 7e107acab6c37ca42b82ebec3ed1a3c3, type: 3}
m_Name:
m_EditorClassIdentifier:
damage: 0.05
damage: 1
offset: {x: 0, y: 0}
size: {x: 1, y: 1}
--- !u!61 &8419934415272737179
Expand Down
2 changes: 1 addition & 1 deletion Awkna/Assets/Prefabs/Tiles/VerticalLaser.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -5023,7 +5023,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 7e107acab6c37ca42b82ebec3ed1a3c3, type: 3}
m_Name:
m_EditorClassIdentifier:
damage: 0.05
damage: 1
offset: {x: 0, y: 0}
size: {x: 0.2, y: 0.91}
--- !u!61 &4498124213436643173
Expand Down
8 changes: 0 additions & 8 deletions Awkna/Assets/Prefabs/tileGroups/New Folder.meta

This file was deleted.

16 changes: 8 additions & 8 deletions Awkna/Assets/Scenes/vlod.unity
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ PrefabInstance:
- target: {fileID: 7682216459154456121, guid: 560e7cf02fd40784cbc15a83daf36f5e,
type: 3}
propertyPath: m_RootOrder
value: 2
value: 3
objectReference: {fileID: 0}
- target: {fileID: 7682216459154456121, guid: 560e7cf02fd40784cbc15a83daf36f5e,
type: 3}
Expand Down Expand Up @@ -311,7 +311,7 @@ PrefabInstance:
- target: {fileID: 1934179596721129191, guid: 063a8957bc34b8145807bc05f490728b,
type: 3}
propertyPath: m_RootOrder
value: 5
value: 6
objectReference: {fileID: 0}
- target: {fileID: 1934179596721129191, guid: 063a8957bc34b8145807bc05f490728b,
type: 3}
Expand Down Expand Up @@ -371,7 +371,7 @@ PrefabInstance:
- target: {fileID: 2115697293169691698, guid: bf3a358f9b08ebc4d9c46bd9db36f6b8,
type: 3}
propertyPath: m_RootOrder
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2115697293169691698, guid: bf3a358f9b08ebc4d9c46bd9db36f6b8,
type: 3}
Expand Down Expand Up @@ -791,7 +791,7 @@ PrefabInstance:
- target: {fileID: 180946403886411843, guid: 86600c4129512014091ea5ae47d31edb,
type: 3}
propertyPath: m_RootOrder
value: 1
value: 2
objectReference: {fileID: 0}
- target: {fileID: 180946403886411843, guid: 86600c4129512014091ea5ae47d31edb,
type: 3}
Expand Down Expand Up @@ -941,7 +941,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1463730990
PrefabInstance:
Expand Down Expand Up @@ -993,7 +993,7 @@ PrefabInstance:
- target: {fileID: 315591677724984562, guid: 28b27b8e0a23230488cde8dfb38956a5,
type: 3}
propertyPath: m_RootOrder
value: 7
value: 0
objectReference: {fileID: 0}
- target: {fileID: 315591677724984562, guid: 28b27b8e0a23230488cde8dfb38956a5,
type: 3}
Expand Down Expand Up @@ -1058,7 +1058,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1967964819
MonoBehaviour:
Expand Down Expand Up @@ -1150,7 +1150,7 @@ PrefabInstance:
- target: {fileID: 1118233206555145323, guid: 344bf6e084236704aaf0f239317af239,
type: 3}
propertyPath: m_RootOrder
value: 6
value: 7
objectReference: {fileID: 0}
- target: {fileID: 1118233206555145323, guid: 344bf6e084236704aaf0f239317af239,
type: 3}
Expand Down
59 changes: 36 additions & 23 deletions Awkna/Assets/Scripts/New Player/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public static PlayerController Instance
public float movementSpeed = 40f; // The speed at which the player is moving.
public float jumpForce = 400f; // Amount of force added when the player jumps.
[Range(0, .3f)]
[SerializeField]
private float horizontalMovementSmoothing; // How much to smooth out the horizontal movement.
public float horizontalMovementSmoothing; // How much to smooth out the horizontal movement.
public bool facingRight = false; // For determining which way the player is currently facing.
[HideInInspector]
public bool isGrounded; // Whether or not the player is grounded.
Expand Down Expand Up @@ -72,28 +71,27 @@ enum GravityDirection { Down, Up };
public bool switchGravityPower; // Turn on or off the gravity switch ability.
public GameObject energyUI; // Turn on or off the energy bar from the UI.

public Animator Animator { get; private set; }
public Animator anim { get; private set; }
public float GetHorizontalMoveInput()
{
return horizontalMoveInput;
}

public float knockback;
public float knockbackLength;
public float knockbackCount;
public bool knockFromRight;
#endregion


private void Awake()
{
FindObjectOfType<AudioManager>().Play("levelstart");
energy = maxEnergy; // Start with max energy.
rb = GetComponent<Rigidbody2D>(); // Get the rigidbody component from the player object.
Animator = GetComponent<Animator>(); // Get the animator component from the player object.
initialGravity = rb.gravityScale; // Get the initial value of the gravity.
m_GravityDirection = GravityDirection.Down; // Initialize the gravity direction with down.
Physics2D.IgnoreLayerCollision(15, 20, true); // Ignore the collition between the player and the collectables.
//Physics2D.IgnoreLayerCollision(20, 20, true); // Ignore the collision between the collectables.
Physics2D.IgnoreLayerCollision(15, 12, true); // player, enemies
Physics2D.IgnoreLayerCollision(12, 12, true); // enemies
Physics2D.IgnoreLayerCollision(12, 19, true); // enemies, chest/crate
Physics2D.IgnoreLayerCollision(13, 15, true); // Ignore the collision between the player and the bomb.
energy = maxEnergy;
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
initialGravity = rb.gravityScale;
m_GravityDirection = GravityDirection.Down;
}

private void Update()
Expand Down Expand Up @@ -122,7 +120,7 @@ private void Update()
{
if (Input.GetButtonDown("Jump") && (isGrounded || isSwinging || isClimbing))
{
Animator.SetTrigger("takeOf");
anim.SetTrigger("takeOf");
rb.velocity = Vector2.up * jumpForce;
isJumping = true;
jumpTimeCounter = jumpTime;
Expand All @@ -148,11 +146,11 @@ private void Update()

if (isGrounded || isSwinging)
{
Animator.SetBool("isJumping", false);
anim.SetBool("isJumping", false);
}
else
{
Animator.SetBool("isJumping", true);
anim.SetBool("isJumping", true);
}
}
else // The same things apply to the reversed gravity.
Expand Down Expand Up @@ -244,21 +242,36 @@ private void FixedUpdate()
if (!isSwinging)
{
//animator.SetBool("IsSwinging", false);
Physics2D.IgnoreLayerCollision(15, 19, false);
Physics2D.IgnoreLayerCollision(15, 19, false); // player, crate


Vector3 targetVelocity = new Vector2(horizontalMoveInput * movementSpeed, rb.velocity.y); // Move the character by finding the target velocity...
rb.velocity = Vector3.SmoothDamp(rb.velocity, targetVelocity, ref velocity, horizontalMovementSmoothing);
} // ...and then smoothing it out and applying it to the character.
Vector3 targetVelocity = new Vector2(horizontalMoveInput * movementSpeed, rb.velocity.y);
if (knockbackCount <= 0)
{
rb.velocity = Vector3.SmoothDamp(rb.velocity, targetVelocity, ref velocity, horizontalMovementSmoothing);
}
else
{
if (knockFromRight)
{
rb.velocity = new Vector2(-knockback, knockback);
}
else
{
rb.velocity = new Vector2(knockback, knockback);
}
knockbackCount -= Time.deltaTime;
}
}
#endregion

if (horizontalMoveInput == 0)
{
Animator.SetBool("isRunning", false);
anim.SetBool("isRunning", false);
}
else if (isGrounded)
{
Animator.SetBool("isRunning", true);
anim.SetBool("isRunning", true);
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion Awkna/Assets/Scripts/Other Scripts/KillTile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private void Update()
}
else
{
PlayerStats.Instance.TakeDamage(damage);
PlayerStats.Instance.TakeDamage(damage, transform.position);
}
}
#if UNITY_EDITOR
Expand Down
41 changes: 25 additions & 16 deletions Awkna/Assets/Scripts/Other Scripts/PlayerStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@ private void Awake()
private int gemNumber = 0;
[SerializeField]
private float ropeMaxCastDistance = 5f;
private float countdownTimeToInvulnerability = 0;
[SerializeField]
private float invulnerabilityTime = 0.2f;

private bool invincible = false;
[SerializeField]
private float knockbackPwr;
private float invulnerabilityTime = 0.2f;

private int usesUsed;
private int numberOfUses = 2;
Expand Down Expand Up @@ -137,43 +135,54 @@ public void Heal(float amount)
/// <param name="dmg">The amount of damage the player takes.</param>
public void TakeDamage(float dmg, Vector2 pos)
{
if (countdownTimeToInvulnerability <= 0)
if (!invincible)
{
health -= dmg;

invincible = true;

FindObjectOfType<AudioManager>().Play("damagetaken");//play sound

PlayerController.Instance.Animator.SetTrigger("getDamaged");
PlayerController.Instance.anim.SetTrigger("getDamaged");

GameObject.FindGameObjectWithTag("MainCamera").GetComponent<CameraShakeController>().Shake();

GameObject.FindWithTag("Player").GetComponent<RopeSystem>().ResetRope();

PlayerController.Instance.Knockback(knockbackPwr, (Vector2)PlayerController.Instance.transform.position, pos.x);
PlayerController.Instance.knockbackCount = PlayerController.Instance.knockbackLength;

countdownTimeToInvulnerability = invulnerabilityTime;
if (pos.x > PlayerController.Instance.transform.position.x)
{
PlayerController.Instance.knockFromRight = true;
}
else
{
PlayerController.Instance.knockFromRight = false;
}

Invoke("resetInvulnerability", invulnerabilityTime);

ClampHealth();
}
else
{
countdownTimeToInvulnerability -= Time.deltaTime;
}
}
public void TakeDamage(float dmg)
{
health -= dmg;

FindObjectOfType<AudioManager>().Play("damagetaken");//play sound

PlayerController.Instance.Animator.SetTrigger("getDamaged");
PlayerController.Instance.anim.SetTrigger("getDamaged");

GameObject.FindGameObjectWithTag("MainCamera").GetComponent<CameraShakeController>().Shake();

countdownTimeToInvulnerability = invulnerabilityTime;


ClampHealth();
}

private void resetInvulnerability()
{
invincible = false;
}

/// <summary>
/// Add one health to the players stats.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Awkna/Assets/Scripts/Other Scripts/SpawnBomb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private void Update()
{
if (objectsToDamage[i].CompareTag("Player")) // If the bomb collides with the player at explosion, ...
{
PlayerStats.Instance.TakeDamage(PlayerStats.Instance.MaxHealth); // ...damage the player.
PlayerStats.Instance.TakeDamage(PlayerStats.Instance.MaxHealth, transform.position); // ...damage the player.
}
else if (objectsToDamage[i].CompareTag("Enemy")) // If the bomb collides with an enemy at explosion,...
{
Expand Down
Loading

0 comments on commit b1ac1e4

Please sign in to comment.