Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Code seems to be ignoring an if statement aside from start.

$
0
0
I can't seem to find a way around this problem, an enemy I have is suppost to dive at the player like a bird, then pull up after colliding with either the player or floor. And upon reaching it's original y pos, startHeight, begin to fly straight again. the if statement triggers at the start when I hit play. but upon diving and returning up it just keeps it's angled movement. if (transform.position.y == startHeight){ Debug.Log ("flying"); walkingDirection = -1.0f; triggertest = false; } is one thing that it seems to ignore if(walkingDirection == -1.0f) { transform.position = Vector3.Slerp (transform.position, transform.position - transform.right, Time.deltaTime * walkSpeed); }else if(walkingDirection == -2.0f){ //rigidbody2D.velocity = new Vector2 (walkSpeed,airSpeed); transform.position = Vector3.Slerp(transform.position,transform.position-transform.right-transform.up, Time.deltaTime*walkSpeed); }else if(walkingDirection == -3.0f){ airSpeed = 8; //rigidbody2D.velocity = new Vector2 (walkSpeed,airSpeed); transform.position = Vector3.Slerp(transform.position,transform.position+transform.up, Time.deltaTime*walkSpeed); } void OnCollisionEnter2D(Collision2D other){ /* * This is for when the bird enemy hits the player * and will have it ascend afterwards */ if (other.gameObject.name == "Player") { if (MovementType == MovementTypes.bird){ Debug.Log ("Bop"); walkingDirection = -3.0f; triggertest = true; } }else if (other.gameObject.tag == "floor"){ if (MovementType == MovementTypes.bird){ Debug.Log ("Ouch!"); walkingDirection = -3.0f; triggertest = true; } } }

Viewing all articles
Browse latest Browse all 7934


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>