- Home /
How to rotate and move gameobject at same time on key press
I want to rotate and move gameobject at same time on keypress but it only do one thing . In my code it only move the game object , I want to rotate it as well.......
if (Input.GetKey(KeyCode.D)) {
transform.Rotate(0,0,-( speed * Time.deltaTime));
transform.Translate (Vector3(-0.5,0,0) * Time.deltaTime*speed);
}
Plz help
What is the scenario? Are you emulating a 2D controller or a controller for moving in 3D space?
I just tried it and it works. $$anonymous$$aybe the problem is somewhere else?
@agosmrt_co: at my side it only translate, no rotation occur :(
Answer by meat5000 · Aug 28, 2013 at 01:02 PM
Nothing wrong with that. Works for me; however I tried it on an object with no rigidbody.
I'm thinking, as its a rotation around z it's not working for you for one of two reasons.
1) You have a rigidbody on the object and the gravity is preventing z-rotation.
2) You have frozen rotation
Your answer
![](https://koobas.hobune.stream/wayback/20220613113052im_/https://answers.unity.com/themes/thub/images/avi.jpg)