InteractableItem target;
private void Update()
{
if (target != null && target.name == "kid_from_space_helmet")
objToThrow.transform.position += (target.transform.position - objToThrow.transform.position).normalized * 2f * Time.deltaTime;
if(Vector3.Distance(objToThrow.transform.position, target.transform.position) < 1f)
{
objToThrow.transform.position += (objToThrow.transform.position - target.transform.position).normalized * 2f * Time.deltaTime;
}
}
The object is moving to the target but never moving back. This IF is not working good :
if(Vector3.Distance(objToThrow.transform.position, target.transform.position) < 1f)
My guess is that the problem is that when the object distance is less then 1 he try to move back but then he is not less then 1 anymore. but anyway it's not working.
I want to move the object to the target then wait 1 second at the target and then to move the object back.
yield return new WaitForSeconds(.1f);
for your delay, some kind of state like abool isGoingBack = true;
to tell your object to go back... \$\endgroup\$