- Home /
Rotate a GameObject without affecting the direction of motion?
Hello Devs,
STATEMENT:
I am creating a mechanic of an object falling down under the action of gravity. I then control it by tilting the iPad and evading the obstacles on the way down. I am scripting for the object and I wanted the object to rotate left a bit if I move left, right a bit if I move right, up a bit if I move up and finally down a bit if I tilt the ipad down. Now the whole point is the object has to restore to its neutral position if it is not moving on it's respective side.
CODE :
if(MOVE)
{
dir = new Vector3(-accel.y, 0 , accel.x);
//Limiting the 'dir' variable to magnitude 1;
if (dir.sqrMagnitude > 1)
dir.Normalize();
//Moving the object at a velocity as defined in speed
transform.Translate((dir.x * speed* Time.deltaTime), 0, (dir.z * speed* Time.deltaTime),Space.World);
//I tried rotation and look at function, but it does not seem to work fine.
//transform.LookAt(dir);
//transform.Rotate(dir*Time.deltaTime*25);
}
PROBLEM : It does not rotate. Even though it does, it does not regain the normal position nor is the rotation fluid.
Your help is much appreciated.
Thank you.
Karsnen.
Your answer
Follow this Question
Related Questions
Control Ship and Gun Separately 2 Answers
Transform - GameObject? 1 Answer
Camera rotation the same as player rotation 1 Answer
transform.rotation doesn't stop 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers