Search code examples
c#vectortrigonometrydirection

Easy Trig - Move an object in a position


I know this is quite easy trigonomety, however I was never introducted to vectors etc, and I'm at a loss understanding how this works.

Given an object at point XY, and a direction N, how do you move that object in that direction?

Also, given am object at point XY, and a destination at point XY, how do you move an object towards the destination?

I understand there is some need for adding vectors etc.

Could somebody please refer me to some easy material to digest?

Thanks.


Solution

  • Given an object at point XY, and a direction N, how do you move that object in that direction?

    If your point is (X,Y) and your direction is a vector (NX, NY), you simply add those two. Now your object is at the position (X + NX, Y + NY).

    Also, given am object at point XY, and a destination at point XY, how do you move an object towards the destination?

    If your source point is (SX, SY) and your destination point is (DX, DY), you usually move the object along (SX + t * (DX - SX), SY + t * (DY - SY)) with t = 0..1