# Math Help Wanted

Help please, Math solution with sine wave and dot product.

I have a directional world vector point that would be the center point of the waves (m_DirectionPoint) each sphere in the screen-shot above is a vector point that needs to pass the sine wave through towards the center point, code below.

``````var direction = Vector3.Normalize (m_DirectionPoint - point);
point.Set (0.0f, Mathf.Sin (Vector3.Dot (direction, point)), 0.0f);
``````

My problem is that I’m using world vectors and need it to be that way too, when my m_DirectionPoint is of Vector3.zero value, everything is right, but when the center point value is changed to Vector3(8.0f, 0.0f, 8.0f), the follow results in the screen-shot below, and if I go out further to a center point value of Vecto3(128.0f, 0.0f, 128.0f) the following result in the screen-shot further below.

Both m_DirectionPoint and point vector variables need to be of world positions, where m_DirectionPoint could be anywhere and all waves move towards the center.

Is this possible to-do with pure Math?

You need to make direction relative to m_Direction point, making it local for the calculatioon. This can be done with a simple subtraction. To help you understand this better, modify the script to use a game object’s transform, and use the LOCAL origin (which will always be 0,0,0) to generate the wave in local coordinates. Then move the object around to see that this is indeed solved by purely mathematical means (a local to global transform).

The solution is to subtract the vector to the object’s origin before doing the wave calculation, and later adding it back to the final point.

Sorry not sure if I’m understanding you correctly, all vectors are in world space, but are you referring to the direction variable?

``````var direction = Vector3.Normalize (m_DirectionPoint - point);
``````

You need to subtract the vector to m_directionPoint from m_direction and point before you calculate direction. This will make m_Direction always to zero, and point becomes (point-m_directionPoint)

In the final step, after you set the point, you need to add the value of m_directionPoint back in by simply adding it.

Would you mind sharing a code snippet?

Thank you Kindly sir, took me a little to understand, but everything working perfectly, cheers

``````var direction = Vector3.Normalize (m_DirectionPoint - point);
point -= m_DirectionPoint;
point.Set (0.0f, m_DirectionPoint.y + Mathf.Sin (Vector3.Dot (direction, point)), 0.0f);
``````