# How to rotate a rigidbody with limited angles and physics?

I need to rotate an object through input but limit the rotation angle. Also I need to put some weight at every corner of the plane and make it affect the plane’s rotation. Right now I can only rotate the plane with limited angles without physics. Here’s the code;

``````  void Update()
{

if (Input.GetKey("up"))
{
curAngle.x += rotSpeed * Time.deltaTime;
}

if (Input.GetKey("down"))
{
curAngle.x -= rotSpeed * Time.deltaTime;
}

if (Input.GetKey("left"))
{
curAngle.z += rotSpeed * Time.deltaTime;
}

if (Input.GetKey("right"))
{
curAngle.z -= rotSpeed * Time.deltaTime;
}

curAngle.x = Mathf.Clamp(curAngle.x, -15, 15);
curAngle.z = Mathf.Clamp(curAngle.z, -15, 15);

transform.eulerAngles = initialAngles + curAngle;
}
``````

I need to change this so I can move it adding force to simulate this “weight control” effect. Thanks for the attention in advance.

do you want it to slowly approach this limit and turn more slowly as it approaches it or you want it to maintain a constant speed and then lock up?

you could use joints to lock the movement realistically and easily for example.

What force is locking it up that your trying to simulate?

Thanks for the answer. I’m making a game like marble, but instead of moving the ball, the player moves/rotates the board. Right now the board has a constant movement that locks up when “hit” the limit. The effect that I want to achieve is kinda like the movement used on nintendo wii’s Marble Balance (a little smooth) and “reset” the board rotation when the player releases the key, like if the board was tied to a rubber band to another object.