x


Adding y position?

ok i jsut need to move my camera up a few y positions

example

transform.position.y = transform.position.y +90;

Whats wrong with that? if transform is the camera

more ▼

asked Nov 16 '10 at 10:49 PM

RaulDiaz gravatar image

RaulDiaz
2 3 3 5

(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

You could try a tralslation instead.

transform.Translate(Vector3.up * 90, Space.World);
more ▼

answered Nov 17 '10 at 09:05 AM

denewbie gravatar image

denewbie
717 3 3 17

The Space.World ensures it moves with respect to world. For local translation just use: transform.Translate(Vector3.up * 90);

Nov 17 '10 at 09:07 AM denewbie

Thanks for enlightening me along the way. I always went for the long version (see my answer). It just struck me how much more elegant your method is :)

Dec 06 '10 at 11:32 PM Statement ♦♦
(comments are locked)
10|3000 characters needed characters left

Why you dont easily put

transform.localPosition.y += 90;
more ▼

answered Dec 07 '10 at 12:22 AM

Uriel_96 gravatar image

Uriel_96
945 61 70 81

Exact duplicate. It doesn't work in C# either.

Dec 07 '10 at 12:26 AM Statement ♦♦

OK, I'm geting confuse, what he wants is this but in C#???

Dec 07 '10 at 12:42 AM Uriel_96

if you need it with C# you only need to see this page http://unity3d.com/support/documentation/ScriptReference/Transform-localPosition.html and change java script to C#

Dec 07 '10 at 12:46 AM Uriel_96
(comments are locked)
10|3000 characters needed characters left

I assume this is C# code. In C#, you can't modify struct fields on properties directly because properties return a copy of the value. It would make no sense to modify a field on a local copy.

I present two options.

As denewbie says:

transform.Translate(Vector3.up * 90, Space.World); 

And the long hand version:

Vector3 position = transform.position;
position.y += 90;
transform.position = position;

You decide what makes the cleanest solution.

more ▼

answered Dec 06 '10 at 11:31 PM

Statement gravatar image

Statement ♦♦
20.1k 35 70 175

(comments are locked)
10|3000 characters needed characters left

Nothing is wrong with it, though you could shorten it by writing

transform.position.y += 90;
more ▼

answered Nov 16 '10 at 10:53 PM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

Cannot modify the return value of 'UnityEngine.Transform.position' because it is not a variable (CS1612)

Does not work in C#

Nov 17 '10 at 10:31 AM Proclyon

Hi. for C# you cant modify a singe values you have to do it like this:

transform.position = new Vector3(transform.position.x, transform.position.y+90, transform.position.z );

I find it a pain so i just just Translate

Nov 17 '10 at 11:47 AM denewbie

You just double posted my comment here aswell and voted me down on the double answer. Isn't that slightly hypocritical? Ah well whatever. As long as it gets an accepted answer somehow. Cba flamewars

Nov 17 '10 at 12:08 PM Proclyon
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5086
x3009
x887
x665
x43

asked: Nov 16 '10 at 10:49 PM

Seen: 2977 times

Last Updated: Nov 16 '10 at 11:04 PM