- Home /
(2D) How to make kinematic rigidbodies rotate without clipping?
Hey! I just started learning Unity, and I ran into a problem. I can't really find the answer myself, but if it was asked before, sorry. So I'm making a 2D game where you need to rotate the level to make a ball fall into a hole, but you can only see in a very small area around you. I'm just making a prototype thing now, and I have the ball and lighting done, along with a reset button (R). Now I'm trying to get the platform to rotate properly when I press A or D. The rectangle I'm trying to rotate is a child of the "Level" empty gameobject. The Level has to stay in one place and should only be able to rotate. What I have now kind of works, but because it's not a rigidbody (which prevents it from falling), it slightly clips through the ball. here's the code: #pragma strict var OriginalRot = transform.rotation; function Start () {
}
function Update () {
if(Input.GetKeyDown(KeyCode.A)||Input.GetKey(KeyCode.A))
{
transform.Rotate(Vector3.forward, 2);
}
if(Input.GetKeyDown(KeyCode.D)||Input.GetKey(KeyCode.D))
{
transform.Rotate(Vector3.forward, -2);
}
if(Input.GetKeyDown(KeyCode.R))
{
transform.rotation = OriginalRot;
}
}
The clipping isn't very serious, but it can be a major problem later and I want it out of my way now. I tried making it a rigidbody, but gravity made it fall. I made it kinematic to stop if from falling, but then the rigidbody's addtorque doesn't work. What should I do to make it not clip, be able to rotate and stop when I want to, or at least have some inertia stopping it, while not being affected by gravity?
Any help is well appreciated! thanks in advance :D
Answer by bundibundi · Apr 28, 2015 at 04:40 AM
Try Rigidbody.MoveRotation
http://docs.unity3d.com/ScriptReference/Rigidbody.MoveRotation.html
Your answer
Follow this Question
Related Questions
how to rotate 2d obj on android 1 Answer
rotate object that has FixedJoint2D 1 Answer
Its this possible? 1 Answer
[Help] Object flips around when using transform.Rotate 3 Answers
Rotating a 2D GameObject on Z regardless of the distance. 2 Answers