- Home /
Question by
Bustahemo · Feb 28, 2017 at 07:41 AM ·
vector3.movetowards
My first game. Pong paddle question.
I am in the process of setting the game to instantiate a ball into the playing field and in doing so, it broke my code to have the comp paddle follow it. (vector3.movetowards)
Now, the question is how to solve this. Being a prefab, I cannot set it as a public gameobject, so I know i'll need to find it using a tag.
What bit of code am i missing?
Comment
After playing around for a bit more, I realized that I was just going about things the wrong way.
What I had needed to do was establish a GameObject and then follow it up by finding a tag:
GameObject ball = GameObject.FindGameObjectWithTag("Ball");
Then, in the Vector3.$$anonymous$$oveTowards sections, it would be:
transform.position = Vector3.$$anonymous$$oveTowards (transform.position, new Vector2 (transform.position.x, ball.transform.position.y), speed * Time.deltaTime);
Your answer
