Transform to Vector3 conversion?

Im running into a math issue where I am attempting to add a Vector3 and a Transform. How do I turn the Transform into a Vector3?

2 Likes

You can’t; a Transform is a component that has position, rotation, and scale (among other things). A Vector3 is a struct which contains 3 floats.

–Eric

Is there not a way to extract the vector information from the transform so I can assign it to a Vector3?

You’re imagining that a Transform is something that it’s not. There’s plenty of “vector information” accessible via a Transform. Take what you need.

http://unity3d.com/support/documentation/ScriptReference/Transform.html

A vector3 is XYZ values. A transform inherits XYZ values natively by default, as does every mesh in 3D space, therefore transform is already a vector3.

There’s something wrong with how you’re coding.

What are you trying to do? What’s your code?

This understanding is wrong. You and terminal205 both need to read that manual page.

2 Likes

Like to explain to me what I’m not understanding?

2 Likes

I think between what Eric, the manual, and I said, it’s pretty clear. My theory is that both of you think that a Transform is the same thing as the position of a Transform. Or, maybe you think that position, rotation, and scale are floats. If the latter, no, that doesn’t make sense. They’re all three floats, i.e. Vector3.

Why would the position of a transform be the same as a transform? They’re values for the transform, they aren’t the actual transform?

I don’t know what’s going on in your head, but if you can sort through it, and post what you thought, and how you came to realize it was incorrect, maybe you’ll have helped terminal205, because neither of you grokked it to begin with. Reading the first few chapters of a book on object-oriented programming might be helpful to you.

As Jessy said, look at the docs about Transform. See all the variables and functions? Those are what a Transform has, and obviously that can’t be converted to a Vector3. If there’s any particular part of a Transform that you want converted to a Vector3, looking that that page should make it pretty obvious what you’d do.

Except rotation. :wink:

–Eric

yes , I know that this post is old…
however it is an issue that I ran into recently. I came across this post while trying to figure out something, and realized that the original question was never answered. There was obviously a couple of differences in point of view…

that being said;
a transform is not a set of coordinates (x,y,z)… however it does have properties of variables that can be called like local position, or a worldToLocalMatrix , or even functions like TransformPoint that can all help obtain that vector3 that the original question was asked about.

I only spent the time answering this so that anyone else that might be confused about the issue might “get it”

and yes spend some time in the scripting reference
the information previously posted about transforms… http://unity3d.com/support/documentation/ScriptReference/Transform.html will help you quite a bit

4 Likes

Necromancy.

Yeah the neckbeard semantics slapfight wasted my time pretty hard. I want Unity to do some conversions and math for me; I don’t want a rehash of Calc3.

All we needed, both OP and I, was this tidbit of info:
transform.position is a Vector3

Was that so hard to type? Did we really need to pull out and compare genitals over this issue?

This is what OP was trying to do and we all know it! Instead of roasting the new guy, maybe just answer the gd question.

Source: Unity - Scripting API: Transform.position

78 Likes

Eric5h5 did tell the OP, though it was structured in a way that can be confused.
“You can’t; a Transform is a component that has position, rotation, and scale (among other things)”
You have to specify what pieces of information you are wanting before you can even begin to attempt getting a Vector3

1 Like

Calm down. You might have needed the position but the OP didn’t say what he needed and you assumed your needs were the same. There are 10 Vector3 properties exposed as part of Transform. What “conversions” would you propose Unity do for you?

1 Like

@vulpineblazeyt Thank you for saying this! I find these smackdowns in response to simple questions among of the most annoying and corrosive aspects of technical help forums.

It’s sad and ironic that the first few responders here felt they were so brilliant that they must point out the wrongness of the OP’s question, but weren’t smart enough to figure out that OP had simply confused “transform” and “transform.position” in the question wording, to which they could have responded in a straightforward, helpful way.

I can’t tell you how often I see threads like this, and it makes me sad.

33 Likes

There were no “smackdowns”, and you’re not helping anything. These thread necros by 1-post users with no interest in contributing anything aside from baseless insults is much worse than any imagined slights on the part of posters who were actually attempting to figure out what the OP meant. Maybe try to understand that being on a technical forum involves being somewhat, you know, technical. Closed.

–Eric

6 Likes