- Home /
Simple movement for NPC C#
Hello,
I'm new to scripting and trying to make a simple NPC script just basic movement forward and backward with turning.
I got some scripts working with collision detection but thats interfering with the players collision so i decided to make a script without collision detection just a simple looping movement.
This is a ping pong script but that's not really what i need i just want something like when hitting a certain position on Z axis turn npc 180 degrees. But whenever i make something like that it keeps on turning when hitting the z axis position. Because it wont stop rotating 180 degrees only when leaving that position. Which is not making the 180 degrees very accurate. Can somebody give me some tips? I would appreciate it thanks in advance.
{
transform.position = new Vector3(Mathf.PingPong(Time.time, 10), transform.position.y, transform.position.z);
}
and this is my script line for turning on an angle:
if(gameObject.transform.position.z > 20){
transform.rotate(0, 180, 0);
,