- Home /
Convert String to Vector or Rotation via Typecasting?
How do you convert a string to a Vector3 or Quaternion? Is the only way to do this via parseFloat for character by character conversion, or is there some more straight forward typecasting?
The usual solution is don't. If a user is entering data, make them enter x/y/z in three boxes. If from a file, put it on three lines (a comma and a newline take the same amount of space.) If you have to hand-parse, String.split can help.
if you have the string in questions, we then can answer your question. cause defining a quaternion can be done in various ways. Are you asking out of the blue or with something specific in $$anonymous$$d?
Is the only way to parse a string to quantity using parseFloat? If so, then it would be like Owen said, make the delimiter easy to string.split(), then convert each entry tofloat, and build the quaternion from that