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

No comments:

Post a Comment

Countdoun set up script ( CountdownManager)

using UnityEngine; using TMPro; public class CountdownManager : MonoBehaviour { public TMP_Text countdownText; public GameObject ca...