- Home /
Instantiate at the wrong position.y
So I have a free falling GameObject. When it hits the ground, I want it to spawn a prefab.
So I did like:
GameObject go = Resources.Load("prefab") as GameObject;
GameObject goo = Instantiate(go);
goo.transform.position = freeFallObject.gameObject.transform.position;
goo.transform.localEulerAngles = new Vector3(90f, 0f, 0f);
However, it seems like the free falling object has and the prefab seem to have a lower position.y then the terrain surface. Is this a Unity bug or did I do something wrong? How can a GameObject drop lower then the terrain surface?
you are not giving any details but it is not a unity bug 99%
Answer by Riki9811 · Aug 17, 2020 at 08:20 AM
Im guessing your free falling object has a rigidbody component attached(unless you are handling the physics yourself). If that's the case have you tried setting the collision detection of the rigid body to continuous? Rigidbodies default it to discrete because it's less processor intensive, but it's also less precise.
You can read more about collision detection here.
I do have a rigidbody component attached on the free falling object. However, for falling, I using CharacterController and modify the velocity separately. Or should I switch the rigidbody to kinematic? Would that help?
I did not use collider for collision detection. I use CharacterController's ground checking.
Answer by TomArano_Dimenco · Aug 17, 2020 at 08:45 AM
its possible to have unity ignore colliders when a free falling objects falls faster than your frame rate.. if 1 frame it is still above the floor and the next frame the position would be below, than no collision would occur..
this might be the problem you are facing, does it work better when you decrease the falling speed?
The object falls on the terrain without going through it, which is good. I'm not sure what method CharacterController uses to detect if it is grounded.