- Home /
Question by
safi07 · Jul 02, 2015 at 08:15 PM ·
movementcuberotatearoundrotatearoundpivot
Rotate a cube around pivot in four direction
I want my cube to drop down to left right up or down with some animation. So what I have done is that I have made an empty game object and made it my cube parent. Now when ever a key is pressed I move the pivot to right position and make it fall in that direction.
It works perfect for left and right but not for up and down please help.
if(roatationAxis=="z")
{
if(rotateDirection=="left")
{
if(transform.localRotation.eulerAngles.z + 10 < rotationAngle)
{
this.transform.RotateAround (transform.position, transform.forward, 10);
}
else
{
this.transform.eulerAngles=new Vector3(0f,0f,rotationAngle);
doAnimate=false;
}
}
else
{
if(transform.localRotation.eulerAngles.z + 10 < rotationAngle)
{
this.transform.RotateAround (transform.position, -Vector3.forward, 10);
}
else
{
this.transform.eulerAngles=new Vector3(0f,0f,rotationAngle);
doAnimate=false;
}
}
}
if(roatationAxis=="x")
{
if(rotateDirection=="up")
{
if(transform.localRotation.eulerAngles.z + 10 < rotationAngle)
{
this.transform.RotateAround (transform.position, transform.right, 10);
}
else
{
this.transform.eulerAngles=new Vector3(rotationAngle,0f,0f);
doAnimate=false;
}
}
else
{
if(transform.localRotation.eulerAngles.x + 10 < rotationAngle)
{
this.transform.RotateAround (transform.position, -transform.right, 10);
}
else
{
this.transform.eulerAngles=new Vector3(rotationAngle,0f,0f);
doAnimate=false;
}
}
}
untitled1.png
(190.1 kB)
Comment
Your answer
Follow this Question
Related Questions
Joystick & RotateAround 1 Answer
Creating a 3D orbital movement 0 Answers
Can you simulate the behavior of Transform.RotateAround using a Rigidbody? 0 Answers
Rotating a Transform around another Transform on the X, Y, and Z Axis 1 Answer
[Android/ iOS] - 3D - touch move, zoom, rotate such as GPS navigation 0 Answers