Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

sprite changes z position without any input to do so

$
0
0
im making a 2d platformer and i have a patrolling enemy but for some reason he changes z position even though i didn't say to and it makes his z position behind the camera so he doesn't render heres the code using System.Collections; using System.Collections.Generic; using UnityEngine; public class EnemyPatrol : MonoBehaviour { public float speed; public float distance; private bool movingRight = true; public Transform groundDetection; void Update() { transform.Translate(Vector2.right * speed * Time.deltaTime); RaycastHit2D groundInfo = Physics2D.Raycast(groundDetection.position, Vector2.down, distance); if (groundInfo.collider == false) { if (movingRight == true) { transform.eulerAngles = new Vector3(0, -180, 0); movingRight = false; }else { transform.eulerAngles = new Vector3(0, 0, 0); movingRight = true; } } } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles