- Home /
Question by
MykalDesign · Apr 03 at 12:44 AM ·
errorbeginnerupdate functionbehaviour
UPDATE: FixedUpdate Issue: AngleAxis stops all other rotation within FixedUpdate. Two types of rotation cannot be calculated?
EDIT: If rotation is in FixedUpdate and AxisAngle is NOWHERE ELSE rotation works. If AxisAngle is in FixedUpdate and Rotation is in Update- they both work. Any other configuration does not work. I would much prefer AxisAngle in Update as it is much more important to have the stable rotation of the object value in FixedUpdate rather than Update which is based on frame rate. Most of my next step equations are based on the Rotation speed being stable enough to have a constant decaying value over time.
public Vector3 vThrownForce; public Vector3 vAxisAngle; public Vector3 vRotationUpwardsForce;
public float fHyzerAngle = 1f;
public float fStabilityAmount = 1f;
public float fRotationSpeed = 1f;
public float fMaxSpeedReached = 1f;
private bool bIsThrown = false;
private bool bTouchedTheGround = false;
void Start()
{
}
void Update()
{
if (Input.GetMouseButtonDown(0) && !bIsThrown)
{
GetComponent<Rigidbody>().isKinematic = false;
GetComponent<Rigidbody>().AddForce(vThrownForce);
bIsThrown = true;
}
if (bIsThrown == true)
{
Debug.DrawLine(transform.position, transform.position + vThrownForce / Physics.gravity.magnitude, Color.red);
if(bTouchedTheGround == true)
{
bIsThrown = false;
}
}
//Rotate();
}
void FixedUpdate()
{
float speed = GetComponent<Rigidbody>().velocity.magnitude;
Rotate();
//transform.rotation = Quaternion.AngleAxis(fHyzerAngle, vAxisAngle);
}
void Rotate()
{
if (bIsThrown == true)
{
//implement rotation and force corelation
//Vector3 sideDir = Vector3.Cross(transform.up, GetComponent<Rigidbody>().velocity).normalized;
//GetComponent<Rigidbody>().AddForce(sideDir * fStabilityAmount);
//GetComponent<Rigidbody>().AddRelativeForce(vRotationForce, ForceMode.Force);
transform.Rotate(Vector3.up, fRotationSpeed * Time.fixedDeltaTime);
}
else
{
GetComponent<Rigidbody>().transform.Rotate(Vector3.up, 0f * Time.fixedDeltaTime);
}
}
private void OnCollisionEnter(Collision collision)
{
if(collision.collider.tag == "ground")
{
bTouchedTheGround = true;
}
}
}
Comment