0
\$\begingroup\$

I need to make an "AI" that makes a ball try to touch the player. But Vector2.MoveTowards()needs a Vector2 variable but how do i get the location of an object?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

As Vector2 is a type composed by two numbers which are x and y, then you should be able to get the position by asking both numbers:

 Vector2 YourVar; 
 YourVar.x; 
 YourVar.y;

So you should use something like:

 SetPositionToMove(YourVar.x,YourVar.y); //if the functions expect x and y or:
 SetPositionToMove(Point2(YourVar.x,YourVar.y)); //if it expects a Point2 for example 
\$\endgroup\$
7
  • \$\begingroup\$ Thank you but i have changed my question becouse I've learned that you can use Vector2.MoveTowards(). Now i need to know how to get the position of an object in Vector2 variable. If you know the answer can you help? \$\endgroup\$ Commented Aug 20, 2015 at 15:19
  • \$\begingroup\$ I couldn't understand what you mean. Can you give an example code? Also i tried using a transform variable (I specified the object using it) but i don't know how to make it a vector2 variable. \$\endgroup\$ Commented Aug 20, 2015 at 15:37
  • \$\begingroup\$ I updated the answer. If I understood it fine, what you want is to get the position (the coords) of a Vector2 variable right? \$\endgroup\$ Commented Aug 20, 2015 at 15:41
  • \$\begingroup\$ One last question: how do i get the x and y coords of an object? \$\endgroup\$ Commented Aug 20, 2015 at 15:45
  • \$\begingroup\$ what type of object? what type do your object has? \$\endgroup\$ Commented Aug 20, 2015 at 15:52

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.