I'm writing a script for my character to pick up objects. I almost have it nailed down but at the moment when the character "picks" the object it stays on the floor, and just gets dragged around as the player moves.
How can I smoothly "lift" this object so that it's y position ends up the same as the center of "this.transform".
Also I would like this to be relative to the players Y position, I've struggled but I finally have a custom gravity script where I can walk on walls, so I need to use the characters Y and not the World Y.
This is my current pick up script:
if (Input.GetKeyDown (KeyCode.Mouse0) && !holding) {
Ray ray = camera.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit)) {
GameObject go = hit.collider.gameObject;
if (go.tag == "BrownCube") {
float dist = Vector3.Distance(go.transform.position, this.transform.position);
if (dist < 2.0f) {
go.transform.parent = this.transform;
hold = go;
}
}
}
}
else if (Input.GetKeyDown (KeyCode.Mouse0) && holding) {
hold.transform.parent = null;
}
↧