private void CreateChild(Vector2 velocity, float magnitude, CS_Projectile_Collision.Owner owner) { GameObject child = Instantiate(gameObject, transform.position, transform.rotation, transform.parent); Rigidbody2D rb = child.GetComponent <Rigidbody2D>(); CS_Projectile_Collision pc = child.GetComponent <CS_Projectile_Collision>(); pc.ChangeOwner(owner); rb.velocity = velocity; child.transform.rotation = Quaternion.LookRotation(rb.velocity); }
private void OnProjectileCollisionEnter2D(Collision2D collision) { CS_Projectile_Collision projectileCollision = collision.gameObject.GetComponent <CS_Projectile_Collision>(); if (projectileCollision.isAvatar()) { if (!CS_WorldManager.Instance.powerupExists && UnityEngine.Random.Range(0.0f, 1.0f) <= 0.2f) { if (transform.position.x > -4.4) { Instantiate(twinShieldPowerUp, transform.position, new Quaternion(), transform.parent); CS_WorldManager.Instance.powerupExists = true; } } Vector3 dir = collision.contacts[0].point - (Vector2)transform.position; dir = -dir.normalized; OnDeath(dir); } }
public override void SpecialCollision(Collision2D collision) { Rigidbody2D rb = GetComponent <Rigidbody2D>(); CS_Projectile_Collision pc = GetComponent <CS_Projectile_Collision>(); float magnitude = rb.velocity.magnitude; float angle = CS_Utils.PointToDegree(rb.velocity); CS_Projectile_Collision.Owner owner = pc.GetOwner(); float angle1 = (angle + 45); Vector2 velocity1 = CS_Utils.DegreeToPoint(angle1); CreateChild(velocity1, magnitude, owner); float angle2 = (angle - 45); Vector2 velocity2 = CS_Utils.DegreeToPoint(angle2); CreateChild(velocity2, magnitude, owner); Destroy(gameObject); }