- Home /
Question by
Jojo B · May 09, 2014 at 11:20 PM ·
c#2d-physicsmouse-look
Need help with Steadying my turning
ok so ive made a physics turning script to use for the Rigidbody2d but currently the object will shake and not look exactly at the point i want so my question is. is there a way to smothe this so the object isn't shaking. also here is my script.
void Update () {
PowerStore += Reactors*10;
float PowFrac = 0;
if (PowerStore > Engines*10){
PowerStore -= Engines*10;
PowFrac = 1f;
}else{
PowerStore = 0;
PowFrac = ( (float)Engines*10f)/( (float)PowerStore);
}
Vector3 Pos = Camera.main.WorldToScreenPoint(transform.position);
Vector3 Direction = Input.mousePosition - Pos;
Debug.DrawLine (Vector3.zero, Direction, Color.red);
float angle = Mathf.Atan2(Direction.y,Direction.x)*Mathf.Rad2Deg;
//print (ReqRot);
float maxA = (PowFrac*Engines*1000)/SWeight;
//float reqA = -(Mathf.Pow(rigidbody2D.angularVelocity,2)/2*(ReqRot-transform.rotation.z));
float CloseAng = Mathf.DeltaAngle(angle,transform.eulerAngles.z);
float MaxV = Mathf.Sqrt(Mathf.Abs(-2*maxA*CloseAng));
print (CloseAng + " : " +MaxV);
if (Mathf.Abs(rigidbody2D.angularVelocity) < MaxV){
rigidbody2D.angularVelocity += maxA*(-CloseAng/Mathf.Abs(CloseAng))*Time.deltaTime;
}
if (Mathf.Abs(rigidbody2D.angularVelocity) > MaxV){
rigidbody2D.angularVelocity -= maxA*(-CloseAng/Mathf.Abs(CloseAng))*Time.deltaTime;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613144656im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Collider just for Tag (2D) (C#) 1 Answer
Rigidbody2D.mass editable during runtime? 0 Answers
How to detect if player is moving. 1 Answer