- Home /
How to stop an object from translating to a desire position?
The Issue:
I'm trying to move a helicopter according to when my player's uses the "UseRadio" animation to call for help. However the helicopter will continue going without stopping at the location I want. The method I'm using below uses hard values. I'm sure unity has something to check this but i haven't found something
Code:
public GameObject HelicopterObject;
public GameObject NPC_Object;
public Animator NPC_Animator;
private float speed = 20f;
private void LateUpdate()
{
if (HelicopterObject.activeSelf)
{
if (HelicopterObject.transform.position.x > 110)
{
HelicopterObject.transform.Translate(Vector3.forward * speed * Time.deltaTime);
HelicopterObject.transform.Translate(Vector3.up * 0.2f * Time.deltaTime);
}
}
}
Image Demo:
Guess you have to do sth like this :
if (HelicopterObject.transform.position.x > 110 && HelicopterObject.transform.position.z < NPC_Object.transform.position.z)
humm this is very lack of info, but, I think you need $$anonymous$$oveTowards on the chopper script, from the current position, to the player pos, a capsule collider set as trigger that cover, on the player pos, from the floor to where the heli will hold the pos (up the player), and OnTriggerEnter on the chopper, so when reach the pos, stop movement and start animations to deploy reinforcements