- Home /
Question by
xxfmxx · Feb 07, 2015 at 06:21 PM ·
collisiononcollisionenterienumerator
Why does my player get pushed away when and after an enemy is spawned
so I basically I want to know why my player is being pushed away every time it collides with the platform the enemy game object is spawned on. im still fairly new to programming (been coding for about a year and a half now )and although I have recently gotten somewhat comfortable with enumerators and loops please try and keep the code simple if possible. heres a youtube link to whats actually happening in my game scene
https://www.youtube.com/watch?v=QuMZcItdGpg&feature=youtu.be
void Update () {
transform.Translate (Vector3.right * Input.GetAxis ("Horizontal") * moveSpeed * Time.deltaTime);
transform.Translate (Vector3.forward * Input.GetAxis ("Vertical") * moveSpeed * Time.deltaTime);
if(Input.GetKey(KeyCode.Space) && isfalling == false)
{
Vector3 v = rigidbody.velocity;
v.y = PlayerSpeed;
rigidbody.velocity = v;
isfalling = true;
}
}
void OnCollisionStay()
{
isfalling = false;
}
void OnCollisionEnter(Collision collision) {
if (collision.gameObject.tag == "Respawn")
StartCoroutine(DieAndRespawn());
Debug.Log("object has been destroyed");
if (collision.gameObject.tag == "MinionS")
StartCoroutine(SpawnEnemey_1stWave());
Debug.Log("enemie has spawned");
}
IEnumerator DieAndRespawn() {
yield return new WaitForSeconds(0.2f);
renderer.enabled = false;
yield return new WaitForSeconds(1.0f);
transform.position = new Vector3(0.0f, 1.45f, 0.0f);
transform.rotation = Quaternion.identity;
renderer.enabled = true;
}
IEnumerator SpawnEnemey_1stWave()
{
Instantiate(minions,transform.position = new Vector3(-32.23f, 0.96f, -10.84f),Quaternion.identity);
yield return new WaitForSeconds(1.0f);
}
}
Comment