# How to calculate the vector direction to point , so the object will move to

This topic is 558 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i like to be able to calculate the vector values from object A to destination position. For Example in this image object A to destination B . What will be the x/y positions all the way until it reach distention B. where the x,y origin is in bottom left side

[attachment=36227:vecmove.png]

##### Share on other sites

A+(B - A)*i

where i = 0..1 value.

##### Share on other sites

i dont understand sorry ,..

##### Share on other sites

i dont understand sorry ,..

You have two points - A & B for example

A (5, 0)_________________________________________________________________________B (10, 0)

You want an equation from which you can get any point inbetween A & B based on some input. A+(B - A)*i is such an equation. If you want to know the midpoint between A & B, you input i = 0.5 and you get
A+(B-A)*i = (5,0) + [ (10,0) - (5,0) ] * 0.5
= (5,0) + (5,0) * 0.5
= (7.5, 0)

If you want to know the last point between A & B which is B itself, then you input i = 1 and you get
A+(B-A)*i = A + (B-A) * 1

= A + B - A

= B

Similarly if you want to get the initial position between A & B which is A itself, then you input i = 0 and you get

A+(B-A)*i = A + (B-A) * 0

= A

The range of i is between [0,1]. If you input i < 0 or i > 1, then the point you get from it is no longer between A & B. You want to generate positions in between when two points are given. This is called linear interpolation.

Edited by newtechnology

##### Share on other sites

Displacement = Destination - Begin

Scale the displacement by a number between 0 (at the beginning) and 1 (at the destination), which represents the normalized displacement, then add the scaled displacement to the starting position. 0.5 would be the halfway point, etc.

Edited by cmac

##### Share on other sites

Thanks allot for the help i got it solved i have another question that is related

How to detect when object A In point B place

i have object which is moving to points in the screen each time the point ( call it B)
is moving to different place and object A follow its direction .
Im using Linear interpolation and simple pythagoras equation to find the vector to point B
what i have problem now is to find the location where object A should stop when it In point B place

point B its just x/y location . point b can be any where on the screen

[attachment=36229:touch.png]

##### Share on other sites

I strongly recommend you go through the Khan Academy course on linear algebra I posted previously. You're asking simple linear algebra questions that apply very broadly to games.

I'm not exactly understanding your question because you know it's at the destination when the interpolation value is 1. If you just want to compare two points in space, measure the distance between them with pythagorean theorem.

##### Share on other sites

I think the question now is about approaching a moving target.

The answer is pretty obvious as soon as you actually implement a seek algorithm. (Assuming you've spent at least 3 minutes studying linear algebra...)

##### Share on other sites
So khathaar is trying to say that when you have two points A objectpos and B destination

You calculate vector with
Vec.x = B.x-A.x
Vec.y = B.y -A.y

Youll need then to normalize it to get direction

You do sqrrt(dot(Vec, Vec)) = vector length

Now you do

Vec.x= Vec.x / vector length
Vec.y = Vec.y / vectorlength

Vec is now direction

1. 1
2. 2
Rutin
21
3. 3
A4L
15
4. 4
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633742
• Total Posts
3013638
×