I made this code for my enemy but it just flickers side to side, anyone know what i could do ?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MonsterAi : MonoBehaviour
{
public float speed;
private bool movingRight = true;
public Transform groundDetection;
// Use this for initialization
void Update()
{
transform.Translate(Vector2.right * speed * Time.deltaTime);
RaycastHit2D groundinfo = Physics2D.Raycast(groundDetection.position, Vector2.down, 2f);
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;
}
}
}
}
↧