How to make something like Xp follow character when player is in trigger?
So like some game I'm trying to make it to were when you get close to Xp the Xp follows you and destroys it self when it hits your collider. I really just need help on how to make it follow you but if you know how to destroy it when it hits the player collider that would be helpful.
Answer by Paricus · Dec 04, 2016 at 10:48 PM
Attach a trigger and a collider to the xp and a rigidbody(check kinematic box). trigger should be larger than collider. then add this code.
xp script
public Transform player;
bool isFollowing = false;
void Update()
{
if (isFollowing)
transform.positon = Vector3.Lerp(transform.position, player.position, 1 * time.deltaTime);
}
void OnTriggerEnter(Collider other)
{
if (other.transform.tag == "Player")
isFollowing = true;
}
Void OnCollisionEnter(Collision other)
{
if (other.transform.tag == "Player")
Destroy(gameobject)
}
Your answer
Follow this Question
Related Questions
Making a league 4 Answers
Help With Score C# Error CS0131 1 Answer
Best Practice for Maze Runner Collectible Scenario - mlagents 0 Answers
Need support on my basic navmesh ai script to follow the player at a certain distance 1 Answer
How can I achieve a homing missile to hover over or near player? 0 Answers