Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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 
share|improve this answer
    
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? –  ElPolloLoco999 Aug 20 at 15:19
    
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. –  ElPolloLoco999 Aug 20 at 15:37
    
I updated the answer. If I understood it fine, what you want is to get the position (the coords) of a Vector2 variable right? –  Megasa3 Aug 20 at 15:41
    
One last question: how do i get the x and y coords of an object? –  ElPolloLoco999 Aug 20 at 15:45
    
what type of object? what type do your object has? –  Megasa3 Aug 20 at 15:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.