Pet Follow Script
Well here I am again, and just to begin this is the first contact I'm having with C# and I figured many things already but I'm having trouble making a following script. I tried to reuse the camera script and make it activated by a collision trigger so when you pass through the object, it starts following you, and at some point you have to be able to drop it. the script is probably all wrong but thats what i could think of... I know what i have to do, but I'm not sure how to put it on code... so if anyone can help me edit this, because so far it didn't work at all D:
public Transform player;
public float smoothTime = 0.5f;
private Vector2 velocity;
private Vector3 akachanPosition;
private Transform akachanTransform;
void Start()
{
akachanTransform = transform;
}
void OnTriggerEnter2D(Collider2D col)
{
if (col.CompareTag("Player"))
{
akachanPosition.x = Mathf.SmoothDamp(akachanTransform.position.x, player.transform.position.x, ref velocity.x, smoothTime);
akachanPosition.y = Mathf.SmoothDamp(akachanTransform.position.y, player.transform.position.y, ref velocity.y, smoothTime);
akachanTransform.position = new Vector3(akachanPosition.x, akachanPosition.y, transform.position.z);
}
}
}
Your answer
Follow this Question
Related Questions
Enemy AI chase, then attack player 1 Answer
Floating Object 0 Answers
How do i tell the camera to only follow the gameObject x orientation 0 Answers
Help with 2D AI scripting 0 Answers