Connecting transform with Vector3

Hello all,

I know this is a much researched question, but after looking for many answers, here it is:
I have an array of points stored as Vector3:

[HideInInspector] public Vector3 [] waypoints;
[SerializeFieald] private Transform[] waypointsTransform;

private void InitializeWaypoints()
{
waypoints = new Vector3 [waypointsTransform.Lenght];

for (int i = 0, i < waypointsTransforms.Lenght; i ++)
{
 waypoints _= waypointsTransforms*.position;*_

}
After initialized, I’m calling its rotation, for the AI’s script:

private void TurnToShelf()
{
Transform pointRotation

pointRotation.rotation = SceneIndex.instance.waypoints [nextWayPoint];

float turningSpeed = 5.0f;

transform.rotation = Quaternion.Lerp(transform.rotation, pointRotation.rotation, turningSpeed * Time.deltaTime);
}

Here I got errors like "cannot convert … vector3 to Quaternion
I just want the AI to face the x direction of the waypoint.

I couldn’t solve but I found a mistake that you wrote [SerializeFieald] instead of [SerializeField] in this line :
[SerializeFieald] private Transform waypointsTransform;

pointRotation.rotation = SceneIndex.instance.waypoints [nextWayPoint];

The above line is the problem. You’re attempting to assign a Vector3 to a Quaternion. You could change the line to

pointRotation.rotation = Quaternion.Euler(SceneIndex.instance.waypoints[nextWayPoint]);

but I would change the waypoints collection to a collection of Transforms instead. That way you get both position and direction stored.

I’ve changed the collection to be of Transforms

 [SerializeField] private Transform[] waypointTransforms;
 [HideInInspector] public Transform[] waypoints;

 private void InitializeWaypoints()
    {
        waypoints = new Transform[waypointTransforms.Length];

        for (int i = 0; i < waypointTransforms.Length; i++)
        {
            waypoints _= waypointTransforms*;*_

}
}
And in AI’s script, it’s Quaternion.Lerp:
Transform pointRotation;

private void TurnToShelf()
{
turningSpeed = 5.0f;

pointRotation = SceneIndex.instance.waypoints[nextWayPoint];
shopper.transform.rotation = Quaternion.Lerp(shopper.transform.rotation, pointRotation.rotation, turningSpeed * Time.deltaTime);
}
It’s not working for me…

obj.transform.Rotate (new Vector3 (0, 0, GameManager.instance.Speed))
or

void Update()
{
     obj.transform.Rotate( new Vector3 (0, 0, GameManager.instance.Speed));
}

or

void Start()
{
     StartCoroutine(RotateNow());
}

IEnumerator RotateNow()
{
      while(true)
      {
           obj.transform.Rotate( new Vector3 (0, 0, GameManager.instance.Speed));

           yield return null;
     }
}

This Probably doesn’t fix your issue, but it might help give you some ideas :slight_smile:

Simple, the collection of waypoints should be of type Transform.
Then, where you access waypoints at the AI script, you should access the rotation variable of the transform.
In this case, there’s no need to store 2 collections. You just need one.