IsKinematic = false doesnt work.
I am trying to make my own Pickup and Drop system. When I pick the object up, I set isKinematic = true, and when i drop it i turn iskinematic = false. Yet every time i try to drop the object, it doesn't fall. it just floats in the air and does nothing. The weird thing is if i delete the object and make a new one it works, but all of the other objects decide not to.
lets say i have a cube and cylinder. I will pickup and drop the cube no problem, but the cylinder work drop it just floats when i drop it. Yet if i delete the cylinder from the Hierarchy and put it back in, the cylinder will drop to the ground but now the cube wont. It makes no sense to me and is really confusing.
Every script is the same. I just switch around the object name like Stick, Block, etc... And i put the scripts the correlating object. Also I've tried Rigidybody.wakeup() but it doesnt work either.
Here is my code:
public class stickPickup : MonoBehaviour {
public Transform itemPosition;
float StickDistance;
public GameObject Stick;
// Use this for initialization
void Start () {
Stick = GameObject.FindWithTag ("Stick");
}
// Update is called once per frame
void Update () {
StickDistance = Vector3.Distance (Stick.transform.position, itemPosition.transform.position);
if (StickDistance <= 2)
if (Input.GetKeyDown (KeyCode.E))
if (GameObject.Find ("Player").GetComponent<FpsController> ().canHold == true)
StickPickup ();
if (GameObject.Find ("Player").GetComponent<FpsController> ().canHold == false)
if (Stick)
if (Input.GetMouseButtonDown(1))
StickDrop ();
}
void StickDrop () {
itemPosition.transform.DetachChildren();
Stick.transform.position = Stick.transform.position;
Stick.GetComponent<Rigidbody> ().isKinematic = false;
GameObject.Find ("Player").GetComponent<FpsController> ().canHold = true;
}
void StickPickup () {
Stick.transform.SetParent (itemPosition);
Stick.transform.position = itemPosition.transform.position;
Stick.transform.localRotation = itemPosition.transform.localRotation;
Stick.GetComponent<Rigidbody> ().isKinematic = true;
GameObject.Find ("Player").GetComponent<FpsController> ().canHold = false;
}
I know i could probably make the script better but im just a beginner. any help would be really appreciated.
Wakeup is usually the problem. You may have just done it wrong. When you try something, it's common to leave it in the code, but commented-out. That makes a record.
Giving it a little push up might also work, so it pops out of your hands (pushes also wake things up.)
Try testing more. Spin around to be sure the object isn't still tracking you. Bump into it. Drop a cube on it to see if it will fall. Usually something it does will give a hint as to the problem (if dropping something on it makes it more, it was a wake-up problem.)
Answer by hawkigamer · Dec 12, 2017 at 04:07 AM
Hmmmm.... i dont know why your not just using gravity instead of kinematic and unless you have a certain reason not to be instantiating and deleting you would be better of instantiating a pickup object deleting the one your holding... but personal opinion, try gravity and messing with the order of execution. (-: hope this helps