I want the object I’m attaching the script to to go to move towards +∞
on the x-axis if the x value of the target is greater than the x value of this object and I want it to go towards -∞
on the x-axis if the target’s value is lower.
The problem is that I don’t know how the calculate whether the x value of the target is greater or lower than the x value of the object I’m attaching this script to.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AIMovement : MonoBehaviour
{
[SerializeField] Vector3 v3Force;
void FixedUpdate()
{
if (// the x value of the target is greater than the x value of the object I'm moving )
GetComponent<Rigidbody>().velocity += v3Force;
if (// the x value of the target is lower than the x value of the object I'm moving )
GetComponent<Rigidbody>().velocity -= v3Force;
}
}