I’m programming a Top Down Space Shooter Game, with Enemies which chasing Player and shoot Lasers
with this script I’m Instantiating them
private void Shoot()
{
if (Vector2.Distance(this.transform.position, Player.transform.position) < 250)
{
GameObject Laser1 = Instantiate(Laser,LaserSpawn1.transform.position, LaserSpawn2.transform.rotation) as GameObject;
Laser1.rigidbody2D.velocity = new Vector3(this.rigidbody2D.velocity.x,this.rigidbody2D.velocity.y,0) + Laser1.transform.up *1000 * Time.timeScale;
GameObject Laser2 = Instantiate(Laser,LaserSpawn2.transform.position, LaserSpawn2.transform.rotation) as GameObject;
Laser2.rigidbody2D.velocity = new Vector3(this.rigidbody2D.velocity.x,this.rigidbody2D.velocity.y,0) + Laser2.transform.up *1000 * Time.timeScale;
}
}
This script is attached for each Laser
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.collider.tag != "Laser" && collision.collider.tag != "Enemy")
{
Instantiate(Explosion, collision.contacts[0].point,Quaternion.Euler(0,0,0));
Destroy(this.gameObject);
}
}
Now if the Laser collides with the chased Player, the Player is accelerated very quickly, the Player is discarded. How can I solve this? The Laser only should be destroyed without speed up the Player
Sorry for my bad englisch