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

Just to be clear for anyone who wants to answer this question, when the key is released, does it swing just once back to the original position, or do you mean by "with gravity" the boat swings back and forth like a pendulum until it comes to rest. And what should happen if the key for left rotation is pressed until the boat is swung far left and then the key for right rotation is pressed?
– robertbuFor robertbu: If release the keys, the rotation oscillates for a few seconds, then stop, yes like a pendulum. (whit the gravity force returns to the original position (photo that is in the middle http://imageshack.us/a/img407/963/pgv.png )). If press the right arrow, the ship rotate in right direction, and if at the same time press the left arrow, the right rotation decrements, and give strength to the left rotation..and vice versa. For give force at the rotation ship, must press left arrow and right arrow, right and left, right and left........ :)
– PaxStyleAre you using a joint? It seems to me if you used a joint you could just apply a force on either the left or right front of the ship and the gravity and slowing down and stuff would just take care of itself
– Slobdell