made a simple playground (finally figured out how to use the playground ).

https://playground.babylonjs.com/#8EVURR#2

can anyone show me how to move my cube to the target using vector subtraction? (so, it’ll move maybe idk slowly to the target).

made a simple playground (finally figured out how to use the playground ).

https://playground.babylonjs.com/#8EVURR#2

can anyone show me how to move my cube to the target using vector subtraction? (so, it’ll move maybe idk slowly to the target).

Operating with vectors

Given 2 lines with each 2 points iterating on each line and drawing lines to their neighbors

2 Likes

Thank you for showing me this; do you have an example of just moving a mesh from point a to point b with a vector? I believe you use vector subtraction an x% each frame.

Subtracting two non-normalized vectors will yield a vector that points in the direction you want to move. Vector.Distance is a way of getting just the distance.

The magnitude (length) of the result from subtracting two vectors tells you how far the total distance between the two vectors is, whereas the normalized vector is the directional components.

Every frame, you can perform that operation and then choose to move your object by whatever % of that distance you wish. ‘Scalar.Lerp’ or Scalar.SmoothStep will perform their respective easing operations on the value given the ratio of start position and end position distances.

Ed: here is an algorithm you might implement:

- Find the direction to move by subtracting two normalized vectors
- Determine how far the object will move in a single unit of time - it’s speed if you will
- Multiply (scale) the normalized direction vector by the speed factor. This gives you the magnitude and direction of the position change of your object
- Add this vector to the moving object’s current world position