Why is a gameobject moves at start?
I have a gameobject with rigidbody2d. My code in FixedUpdate:
void FixedUpdate() {
if (isWobble) {
rb.velocity = new Vector2(-Mathf.Sin(rb.rotation * Mathf.Deg2Rad) * 3.0f, rb.velocity.y);
}
}
And i have a coroutine:
IEnumerator Wobble() {
float speed = 2.0f;
while (isWobble) {
// sine ease in out
float rotation = -80.0f * (Mathf.Cos(Mathf.PI * Time.fixedTime * speed));
rb.rotation = rotation;
yield return new WaitForFixedUpdate();
}
}
start:
void Start() {
isWobble = true;
StartCoroutine("Wobble");
}
When I start the game, my object is shifted slightly to the right. Instead of moving around an axis. What could be the problem?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612102016im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I make a 2D spaceship rotate to my mouse? 0 Answers
Rotate Rigidbody2D by Touch 1 Answer
Inconsistent Velocity? 0 Answers
Make Prefab Rotate Depending on a different Game Object's Rotation. 0 Answers
Object won't move even with velocity 0 Answers