- Home /
How do I properly change from patrol way points to target way points during game play?
I am using the code below. The code accesses the Unity Standard Assets Waypoint Progress Tracker Script (WayPointProgressTracker.cs) to utilize variable pTracker which is a waypoint progress transform. The idea is to switch from a unity provided way point circuit to 2 waypoints parented to a player car. The problem I'm having is everything works in editor mode. In editor mode when you hit play everything updates as it should. It switches to chasing the player car when a collider trigger has been entered and returns to the original waypoint circuit when exiting the trigger. Cool. What's not so cool is if the game is started with game view screen docked and maximize on play is enabled and at this point is playing in full screen mode the AI car no longer chases after the player car. It chases after the waypoint tracker which is no longer pointing to the 2 waypoints attached to the player car for some reason. In fact the way point progress tracker transform teleports to the original starting position of the player car. The same unexpected behavior is observed with a test game build. I have been running around in circles for a really long time trying to figure this out. Any insight would be helpful. Perhaps its in the code. Maybe there is a better way to do what I'm trying to do. At this point what I really need help in understanding is how to force the waypoint progress tracker to follow the waypoint ciruit attached to the player car during maximize on play game play and game play on a build. I have tried this using Unity 5.4.3, Unity 2017.1.1f1 and Unity 2017.2.1f1 thinking that maybe it was a bug but the problem was duplicated on all these other versions of Unity. I have viewed the game log and editor log and no errors appear to be reported. If you need me to provide a copy of the way point progress tracker which is part of Unity Standard Assets then I can post. Any help will be very much appreciated.
using UnityEngine;
//using System.Collections;
using UnityStandardAssets.Utility;
//using UnityStandardAssets.Vehicles.Car;
public class CarChaseScript : MonoBehaviour
{
WaypointProgressTracker pTracker;
void Start()
{
pTracker = transform.parent.parent.GetComponent<WaypointProgressTracker>();
//pTracker.circuit = GameObject.FindWithTag("OriginalWayPointCircuit").GetComponent<WaypointCircuit>();
}
void OnTriggerEnter(Collider playerCar)
{
Debug.Log("trigger");
if (playerCar.tag == ("PlayerCollider"))
{
pTracker.circuit = GameObject.FindWithTag("CarChaseCircuit").GetComponent<WaypointCircuit>();
}
}
void OnTriggerExit(Collider playerCar)
{
pTracker.circuit = GameObject.FindWithTag("OriginalWayPointCircuit").GetComponent<WaypointCircuit>();
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
Problem with Camera when building 1 Answer