Continue rotating/ tilting object after key is released?
So I'm at a bit of a stump, currently I have the object moving up into the air then having the force reset it self, I also have the object tilting towards one side and growing the longer you hold the key down, it also switches to tilt to the other side when I press the key again. The object spinning is just aesthetics so disregard that. Now what I'm looking for is having the accumulated amount of tiltAmount and TiltAddition when the key was pressed to continue to tilt the object when the key is released then when key is pressed once again for the tiltAddition to reset and start adding up again. I have the object tilting on the worlds axis and it rotation and pushing up on its own axis.
Here is what I have:
public float boostForce = 15.0f;
public float boostAddition;
public float tiltAmount = 15.0f;
public float tiltAddition;
public bool hastTiltedRight = false;
public float rotateAmount;
public bool hasRotatedClockwise = false;
private Rigidbody rb;
void Start ()
{
rb = gameObject.GetComponent<Rigidbody> ();
}
void Update ()
{
ContinueToRotate ();
if (Input.GetButton ("Jump"))
{
boostAddition += 1;
tiltAddition += 0.05f;
//Pushes object up in the air with beginning boost force and growing boost additional force.
rb.AddForce (transform.up * boostForce * boostAddition * Time.deltaTime);
if (hasRotatedClockwise == true && hastTiltedRight == true)
{
transform.Rotate (new Vector3 (0, rotateAmount++ * Time.deltaTime, 0));
transform.Rotate (Vector3.left, tiltAmount * tiltAddition * Time.deltaTime, Space.World);
}
else if (hasRotatedClockwise == false && hastTiltedRight == false)
{
transform.Rotate (new Vector3 (0, rotateAmount-- * Time.deltaTime, 0));
transform.Rotate (Vector3.right, tiltAmount * tiltAddition * Time.deltaTime, Space.World);
}
}
if (Input.GetButtonUp ("Jump"))
{
boostAddition = 1;
hastTiltedRight = !hastTiltedRight;
hasRotatedClockwise = !hasRotatedClockwise;
}
}
// Keeping object rotating at accumulated amount when button is released, when button button is pressed again rotate amount is reset
void ContinueToRotate ()
{
transform.Rotate(new Vector3(0,rotateAmount * Time.deltaTime,0));
if (Input.GetButtonDown ("Jump"))
{
rotateAmount = 0;
}
}
void ContinueToTilt ()
{
if (hastTiltedRight == true)
{
transform.Rotate (Vector3.right, tiltAmount * tiltAddition * Time.deltaTime, Space.World);
}
else if (hastTiltedRight == false)
{
transform.Rotate (Vector3.left, tiltAmount * tiltAddition * Time.deltaTime, Space.World);
}
}
}
the function continueToTilt is not being called but that is what i was coming up with, however that wasn't working, its probably way off, anyone know any fixes?
Thanks.