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?
1 Answer
\$\begingroup\$
\$\endgroup\$
7
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
-
\$\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\$ElPolloLoco999– ElPolloLoco9992015-08-20 15:19:05 +00:00Commented 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\$ElPolloLoco999– ElPolloLoco9992015-08-20 15:37:28 +00:00Commented 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\$Megasa3– Megasa32015-08-20 15:41:35 +00:00Commented Aug 20, 2015 at 15:41
-
\$\begingroup\$ One last question: how do i get the x and y coords of an object? \$\endgroup\$ElPolloLoco999– ElPolloLoco9992015-08-20 15:45:48 +00:00Commented Aug 20, 2015 at 15:45
-
\$\begingroup\$ what type of object? what type do your object has? \$\endgroup\$Megasa3– Megasa32015-08-20 15:52:11 +00:00Commented Aug 20, 2015 at 15:52