# Rotation Force

Hi to all!
I would make if I press left arrow the boat rotate at left, and if i press right arrow, the boat rotation is at right… and if I release this two taste, the boat with gravity force, return at the original position… (slowly)

Here’s a picture of the movement that I try to do…
http://imageshack.us/a/img407/963/pgv.png

I did this script, but is no good…
I don’t know how add gravity force, and the rotation is jerky… and if I press the oppost key, instead of slowing down the rotation, immediately goes on the opposite side without rotation…

``````public class RideSchiffschaukel : MonoBehaviour
{
GameObject gondelarm;
float gondelarm_sin;

void Awake()
{
gondelarm = transform.Find("plattform/staender/gondel_arm").gameObject;
gondelarm_sin = 0.0f;
}

void Start()
{

}

//Update viene chiamata ad ogni istante
void LateUpdate()
{
//-- Left arm rotation
if(Input.GetKeyDown(KeyCode.LeftArrow))
{
float arm_rot = Mathf.Sin(gondelarm_sin) * 80.0f;
gondelarm_sin = (gondelarm_sin + Time.deltaTime * 1.0f) % 360.0f;

gondelarm.transform.localEulerAngles = new Vector3(0.0f, 0.0f, arm_rot);
}

//--Right arm rotation
if(Input.GetKeyDown(KeyCode.RightArrow))
{
float arm_rot = - Mathf.Sin(gondelarm_sin) * 80.0f;
gondelarm_sin = (gondelarm_sin + Time.deltaTime * 1.0f) % 360.0f;

gondelarm.transform.localEulerAngles = new Vector3(0.0f, 0.0f, arm_rot);
}
}
}
``````

I’m trying to do this 1 month… but I can’t get…
I hope you can help me, and sorry for my bad english!

Paolo

@Slobdell has the right idea (assuming you are open to using the physics engine). Use a hinge joint. If you haven’t used hinge joints before, here is a video tutorial to get you started:

http://www.unity3dstudent.com/2010/07/beginner-b11-basic-joints/

Here is a possible setup for your game:

• Place an empty game object at the apex of your four support columns. Add a Rigidbody and set the IsKinematic flag to ‘true.’
• Add a Hinge component to the Boat. Make the axis (0,0,1) assuming the camera is looking towards positive ‘Z’. Adjust the anchor ‘Y’ until the hinge is at or near your empty game object from step 1.
• Drag and drop the empty game object from the first step onto the Connected Body variable in the hinge joint.

After all the setup, the script is trivial:

``````   var amount = 5.0;

function Update () {

if (Input.GetKey(KeyCode.RightArrow)) {