Simple waypoint follow AI in unity | Patrolling AI in unity3d | Waypoint system unity

Subscribers:
1,110
Published on ● Video Link: https://www.youtube.com/watch?v=jwhQ3mVQZgE



Duration: 5:15
882 views
20


Code :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MyWayPoint : MonoBehaviour
{

public Transform[] allwayPoints;
public float rotationSpeed = .5f, movementSpeed = 0.5f;
public int currentTarget;

// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

Movement();
Rotate();
ChangeTarget();
}

void Movement()
{
transform.position = Vector3.MoveTowards(transform.position,allwayPoints[currentTarget].position,movementSpeed*Time.deltaTime);
}

void Rotate()
{
transform.rotation = Quaternion.Slerp(transform.rotation,
Quaternion.LookRotation(allwayPoints[currentTarget].position-transform.position),rotationSpeed*Time.deltaTime);

}

void ChangeTarget()
{
if (transform.position==allwayPoints[currentTarget].position)
{
currentTarget++;
currentTarget = currentTarget % allwayPoints.Length;
}
}




}

/////////////////////////////////////////////////////////////////////////////////////////////
ASSALAM o alaikum
All codes and concepts and videos from this channel are non copyrighted and free to use because I believe that knowledge should be freely and easily available for everyone
/////////////////////////////////////////////////////////////////////////////////////////////




Other Videos By Muhammad Shahzaib


2022-09-12Detect Button is held or being pressed in unity easy tutorial
2022-09-11Make world UI always always look at camera unity tutorial | Rotate gameObject towards camera unity
2022-09-04Effect all ui elements in group using Canvas Group unity| Canvas Group in unity
2022-09-04Attach trailer with truck using joints in unity3d
2022-08-31Balance rigidbody in unity3d | Balance rigidbody character from fall on hitting unity
2022-08-31When your game character is too much down to earth
2022-08-29Develop sun in unity3d | Add custom sun in unity3d | Lens flare in unity3d
2022-08-28Enable hinge joint and car door physics on collision unity3d | Simple car hit effect in unity3d
2022-08-27GTA like car doors effect in unity3d | Unity door physics | Hinge joint in unity
2022-08-24Wind Zone in unity | Bend trees using wind zone in unity | How to add trees on terrain
2022-08-23Simple waypoint follow AI in unity | Patrolling AI in unity3d | Waypoint system unity
2022-08-21Add 3D Text in unity3D
2022-08-21Change default editor in unity
2022-08-17Auto adjust Ui elements in grid Unity | Grid Layout group unity
2022-08-16Auto adjust ui elements in a column unity | Vertical Layout group in unity
2022-08-12Analog Clock in unity3d demo with ticking ASMR
2022-08-09Digital Clock in unity full tutorial
2022-08-09UI elements infinite rendering bug and solution
2022-08-08Beautiful waterfall in Karachi
2022-08-07Add trail to bullets in unity3d step by step easy tutorial | #Trail Renderer in unity
2022-08-05Shoot bullet in unity easy tutorial | Tap input | Destroy bullets



Tags:
unity
unity3d
learn unity
unity tutorials
unity Ai
artificial intelligence in unity
patroll in unity
patrolling ai in unity
waypoint system
simple waypoint system
simple waypoint system in unity
artificial intelligence
petrol between waypoints in unity