- Home /
Adjust Y smoothly regardless of object rotation
So, first off I apologize if I do this wrong, this is my first time here.
I'm in the process of self-teaching Unity/C# and starting to get a feel for more involved object movement, and I'm trying to figure out a decent way to change the Y value by a set amount smoothly by pushing + or - without regard to GameObject orientation.
Now, I've read various things, and looked at tons of projects that had some form of similar setup but I seem to just be having an issue getting anything to work the way I want it to, so I was hoping that maybe someone could break it down for me in some way that it makes sense or point me in the right direction.
Basically I have my camera that rotates around an Empty as a "center" that has capability of zooming and free orbit around that center point, and I'm trying to build in the Pan/Trolley controls, but my Up/Down movement is always in relation to the Camera Local Up (still haven't figured out Z movement either, but once I can handle the Up/Down movement, I should be able to tweak it to fit).
Anyway, any sort of help would be appreciated. Though I'm not necessarily asking for anyone to write up the code for me, more just guide an inexperienced but hungry student, so if anything beyond pointing me in the right direction I would prefer pseudo-code at best so I can figure it out on my own. Again, thanks for any help or direction.
Answer by tanoshimi · Oct 01, 2014 at 09:19 PM
Move up in world space:
transform.position += Vector3.up * Time.deltaTime;
Move up in local space:
transform.position += transform.up * Time.deltaTime;
That seems to work just fine, any tips how to get an equivalent "relative" forward motion? I know Vector3.forward will move according to world, but I'd like to move on that same plane of movement, just with the "forward" direction being relative to my Y rotation rather than World.
That would be transform.forward ins$$anonymous$$d of Vector3.forward :)
Well, Vector3.forward is world forward space. transform.forward is object forward space, but what I want is an "artificial forward" that operates like Vector3.forward, but that uses the Y rotation, to define what that "forward direction" is. Basically my camera should be able to face any direction, and have the forward motion only take place on the x/z axes of movement...sort of a hybrid between Vector3.forward and transform.forward. Sorry if that doesn't make sense.