- Home /
Why Rigidbody2D gameobject automatically translating to Vector2.zero itself
Hi all.
Mystery bug occurs once a while. I mean my project work perfectly as i need at most of times.
In my scenario, Series of rigidbody2d ball is shooted by using Ball_Rigidbody2D.AddForce(dir*speed);
.
Ball usually hits the wall and bounce little bit, then falls down on floor.
But in rare case when it hits wall it automatically translate to Vector2.zero itself
If i leave it to occur in loop then it will hit very bad Physics2D.Simulate in Profiler. Later lags like hell.
please watch this video to get clear idea on bug: https://youtu.be/JjdcydDKHMA
Im noob but Im aware of few basics physics rules that rigidbody should not be translated via script. If isKinematic is enabled we can translated via script.
I googled a lot to solve this issue, but sadly didn't found any solution. Please help me to fix this bug.
Thank you in advance :)
Is collision detection code involved (OnCollisionEnter2D)? how are you moving the rigidbody? is it's position altered somewhere in the code?
sorry for late reply. Thank you for responding.
Yes OnCollisionEnter2D is involved. but no problem there
void OnCollisionEnter2D(Collision2D collision) {
if(firstTime == true)
if(collision.gameObject.tag == "Player" || collision.gameObject.tag == "Floor")
{
ExplodeNow();
firstTime = false;
}
}
Im instantiating ball at a point and moving by applying force on ball once using Ball_Rigidbody2D.AddForce(dir*speed);
Ohhh no is$$anonymous$$inenatic enabled
gameobject also automatically translating to Vector2.zero itself
im noob, I may did not obey unity laws of physics, so let me explain how did i implemented.
Falling (bomb) ball is Rigidbody2D, driven using
Rigidbody2D.AddForce(dir*speed);
Square Sprite (Cat) is
is$$anonymous$$inematic
enabled, i'm controlling it usingRigidbody2D.$$anonymous$$ovePosition(Vector2);
Bullet from Cat is
is$$anonymous$$inematic
enabled, i'm controlling it usingRigidbody2D.velocity = Vector2.up*speed;
First i implemented in 3D with this same script, but this bug didnt showedup
please say whether i used anything wrong. thank you in advance :)
Answer by spark-man · Sep 10, 2015 at 01:13 PM
Its unity engine bug. It is fixed after updating to latest version Unity 5.2.0 f3
A guy from Unity Technologies said me in forum.
Your answer
Follow this Question
Related Questions
Rigidbody2D freezes 0 Answers
how to make my character stay stable after hit? 2 Answers
About Rigidbody2D.AddForce's duration... 2 Answers
Collision 2d is not working perfectly 0 Answers
Workarounds for Higher Control When Using Physics2D? 0 Answers