- Home /
Question by
abishekpoudel2014 · Mar 21, 2019 at 03:08 AM ·
errordebug
Making an petrolling ai problem,Trying to make a petroling enemy ai problem
This is the code that i am trying to make a petroling AI and after it goes to the edge it keeps on flipping
public class petrol : MonoBehaviour { public float speed; public Transform groundDetect; bool movingRight = true;
void Update()
{
transform.Translate(Vector2.right * speed * Time.deltaTime);
RaycastHit2D groundInfo = Physics2D.Raycast(groundDetect.position, Vector2.down,5f);
if (groundInfo.collider == false)
{
if (movingRight == true)
{
Debug.Log("goingleft");
transform.eulerAngles = new Vector3(0, -180, 0);
movingRight = false;
}
}
else
{
Debug.Log("Going right");
transform.eulerAngles = new Vector3(0, 0, 0);
movingRight = true;
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612193938im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why am I seeing: error CS0117: `Debug' does not contain a definition for `LogWarning' 1 Answer
Bolt Flowchart is not detecting Script on GameObject 0 Answers
How to resolve UnauthorizedAccessException 0 Answers
My game won't run on the cloud 0 Answers
`UnityEngine.Debug' does not contain a definition for `LogException' 3 Answers