The question is answered, right answer was accepted
Rigidbody behaves very strange and random
Hey guys, I didn't find my problem with google, so I'll try it here.
I'm making a 2D platformer with shooting mechanics. Now what I want the projectile to do is get fired in the direction of the mouse (works) and then behave like a slightly bouncing game object. My problem is, that when I fire the projectile (called blob in this case) it just hangs in the air most of the time. Sometimes the rigidbody behaviours kick in like intended (it falls to the ground and bounces a bit), and I have no Idea why it does or why not. That is mostly random, except when the blob hits another blob that hangs in the air, in which case it is guaranteed that it behaves as it should.
The following code is mostly for testing purposes so don't ask why the movespeed is so slow or why I use Time.countFrames as references to set isKinematic to false. That'll be changed later on along with some realistic force to the projectile when transform.translate has moved it to a certain distance from the player.
public float moveSpeed = 1.0f;
private float instTime;
public float liveTime;
void Start ()
{
rigidbody.isKinematic = true;
instTime = Time.frameCount;
}
// Update is called once per frame
void Update ()
{
liveTime = Time.frameCount - instTime;
if(liveTime < 200)
{
transform.Translate (Vector3.right * Time.deltaTime * moveSpeed);
}
if (liveTime > 200)
{
rigidbody.isKinematic = false;
}
}
It is probably important to note that the blob is getting instantiated inside the player, which is why I use the transform.translate here, but if you have a better solution instead of translate, don't hesitate to tell me ^^
Thanks in advance and have a nice day!
Answer by Fujitaka · Apr 17, 2016 at 06:30 PM
Solved it!
I just replaced the second if-statement with an else-statement (which make more sense anyway) and it worked as intended!