- Home /
Question by
Totenn · Dec 11, 2017 at 02:13 PM ·
gameobject2d gamefollow playerteleporting
Teleporting gameobject 2D
Hello, i am new, I have this ball (GameObject) :
https://imgur.com/a/jriOI (GIF)
I want this ball to follow me(Its my weapon), but its very slowly.. i can increase speed but rotation will be very fast and it will be horrible. how can i make the ball teleporting to me when i am running/jump..... ?
Comment
Answer by KittenSnipes · Dec 13, 2017 at 12:02 AM
This sounds about what you are going for:
//The transform of your pet
public Transform ball;
//The radius
public int radiusCheck = 5;
void Update () {
//If the pet is greater than the radius away from the player
if (Vector2.Distance(transform.position, ball.transform.position) > radiusCheck)
{
//Teleport the ball to the player
ball.transform.position = transform.position;
}
}