• Advertisement
Sign in to follow this  

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

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 this post


Link to post
Share on other sites
Advertisement

i dont understand sorry ,.. 

can you please give more info 

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 this post


Link to post
Share on other sites

https://www.khanacademy.org/math/linear-algebra

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Advertisement