Answers for "Making a vector3 z coord have a zero on reflect?"
http://answers.unity.com/questions/1536298/making-a-vector3-z-coord-have-a-zero-on-reflect.html
The latest answers for the question "Making a vector3 z coord have a zero on reflect?"Answer by ModLunar
http://answers.unity.com/answers/1536328/view.html
Ahh okay I think I know what you mean now (for future Google people, see the comments too, I asked for clarification)
<br><br>
Without looking too much into it, I'd probably force it along the xy-plane by changing it to
<br>
`Mathf.Max (speed, minVelocity) * Vector3.Scale(new Vector3(1, 1, 0), direction).normalized;`
<br>
instead of
<br>
`direction * Mathf.Max (speed, minVelocity);` on line 40 (at the very end)
<br><br>
Vector3.Scale(...) will take 2 Vector3s and multiply their corresponding x, y, and z compenents together, so you can multiply by 1 in the x and y to keep whatever the velocity was in the xy axes, but then multiply by 0 in the z to have the velocity there be zero.
<br><br>
For example, `Vector3.Scale(new Vector3(1, 1, 0), new Vector3(10, 7, 4))` would give you back an expression equal to `new Vector3(10, 7, 0)`
<br><br>
By getting rid of the z-component, you need to re-normalize the vector cause it lost its length of 1. Then once it has a length of 1 again, you can multiply by the speed to give you the right size velocity vector.
<br><br>
And a side note, if you're working with Rigidbodies, you may want to check in the inspector, under "Constraints", turn on "Freeze Position Z" so that it can't move (from forces) in the z-axis. I'd still make that change though in the script if you want them to not "lose out on speed" if their direction was not going to be exactly xy-plane parallel.Tue, 31 Jul 2018 02:36:53 GMTModLunar