- Home /
How do I modify the current transform?
I am trying to take the current transform of my object, and add 5 (or some number) to the Y axis. Right now I am doing this:
transform.position.y += 1;
With that, my object just starts moving up in the air forever. How can I accomplish what I need?
THANKS!
@tatelax: So, if it's "fixed" how about writing an answer that explains what you solved your problem? This site should help other people with the same problem / question to find a solution.
To be honest i'm not completely sure what you want to do. I guess you do this in Update so yes, it would add 1 to y every frame. If you want just move it up once, you should call it only once. If you want a slowly s$$anonymous$$dy movement you need either some logic to detect when it reached your desired endposition, or use Lerp
I thought about posting how I fixed it, but I have no idea how it fixed.
Damn, didn't read the comments before posting an answer.
Oh well.
Answer by FLASHDENMARK · Dec 23, 2011 at 07:57 PM
You want to add a value once?
function Update (){
if(condition){
NewPosition();
}
}
function NewPosition(){
transform.position.y += 5;
}
NB: Just make sure to set 'condition' to false, or make it non-recursive(so it does not execute 'NewPosition' more than you want it to).
Just make sure you only execute the code once. You could also use booleans, but well that is preference.
Answer by hesa2020 · Dec 23, 2011 at 12:47 AM
Its easy here the script :
in c# : transform.position = (new Vector3(transform.position.x,transform.position.y +1,transform.position.z));
I don't want to offend you, but that's exactly the same... Sure in C# the OP's code won't work, but since it works for him it's quite obvious that he uses UnityScript ;)