Friday, July 25, 2025
Ai car controler script c#
Ai car controler script c#
using UnityEngine;
public class AICarFollow : MonoBehaviour
{
public Transform[] waypoints;
public float speed = 10f;
public float turnSpeed = 5f;
private int currentIndex = 0;
void Update()
{
if (waypoints.Length == 0) return;
Transform target = waypoints[currentIndex];
Vector3 direction = target.position - transform.position;
// Move forward
transform.position = Vector3.MoveTowards(transform.position, target.position, speed * Time.deltaTime);
// Rotate smoothly
Quaternion rotation = Quaternion.LookRotation(direction);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, turnSpeed * Time.deltaTime);
// Next waypoint
if (Vector3.Distance(transform.position, target.position) < 2f)
{
currentIndex = (currentIndex + 1) % waypoints.Length;
}
}
}
Then waypoints add kro tb ja ker set krega
Subscribe to:
Post Comments (Atom)
Countdoun set up script ( CountdownManager)
using UnityEngine; using TMPro; public class CountdownManager : MonoBehaviour { public TMP_Text countdownText; public GameObject ca...
-
Learn how to become a special person: You want to know how can you also be a special person.There is no need to know or do anything t...
-
how to make money online Making money online can be a viable option if you're willing to put in time, effort, and sometimes ...
No comments:
Post a Comment