Make a change when reaching an area
So, I want that when the boat reaches a location close to a character, the character rides into the boat automatically, how can I do that? PS: The character riding the boat dosen't have to be animated, just when the boat is close the character position changes and get into the boat, I was thinking about using transform.position to change the charcter position to the boat position, but the main problem is that I couldn't define the distance between the character and the boat for wich the character can get into the boat.
Answer by MT369MT · Aug 14, 2018 at 09:54 PM
Hi, you could add a script to your boat that calculates the distance between the player.
public GameObject Player;
public float MinDistance;
public float CurrentDistance;
void Start()
{
Player = GameObject.Find("Player");
MinDistance = 3;
}
void Update()
{
CurrentDistance = Vector3.Distance(transform.position, Player.transform.position);
if (CurrentDistance <= MinDistance)
{
Player.transform.position = transform.position;
//Player is in boat
}
}
Your answer
Follow this Question
Related Questions
How to open and close a door 0 Answers
Hiding helper geometry during runtime 4 Answers
missing cinemachine Kit tools tutorial menu 0 Answers
TargetPosition of leg spring stuck at 80 0 Answers