- Home /
Question by
NinjaRubberBand · Jul 15, 2015 at 07:32 PM ·
movementobjectaxis
Move object from a to b
I know this sounds like a question which has been asked before. But i cant find any answers on the net, so know im asking! How do i make my object move 2 on the z-axis if i press space?
Comment
Answer by Cherno · Jul 15, 2015 at 07:40 PM
void Update() {
if(Input.GetKeyDown(KeyCode.Space)) {
Vector3 myPos = transform.position;
transform.position = new Vector3(myPos.x, myPos.y, myPos.z + 2f);
}
}
Alternatively:
void Update() {
if(Input.GetKeyDown(KeyCode.Space)) {
transform.position += Vector3.forward * 2f;
}
}
Your answer
Follow this Question
Related Questions
How to get an Objects position per axis? 1 Answer
Rotating a player object without rotating the axis 0 Answers
"Turn off" snapping of gameobjects inside editor? 5 Answers
Objects not showing axis lines? 0 Answers
Axis Issue 1 Answer