- Home /
Gameobject Following Parent Rotation But Not Position?
So i'm making a system where you can pick up and throw objects, but when running the game, i go to pick it up, it works, but it only follows the player's rotation, not it's position.
using UnityEngine;
public class PickUp : MonoBehaviour
{
public Transform dest;
public GameObject knob;
public GameObject player;
public Quaternion rotationOffset;
void OnMouseDown()
{
GetComponent<Rigidbody>().useGravity = false;
GetComponent<BoxCollider>().enabled = false;
this.transform.position = dest.position;
this.transform.rotation = rotationOffset;
this.transform.parent = GameObject.Find("PickupSlot").transform;
knob.SetActive(false);
}
void OnMouseUp()
{
GetComponent<Rigidbody>().useGravity = true;
GetComponent<BoxCollider>().enabled = true;
this.transform.parent = null;
knob.SetActive(true);
GetComponent<Rigidbody>().AddRelativeForce(500, 0, 0);
}
}
how could i fix this?
Is PIckupSlot a transform on the player? Like a socket?
can you share a screenshot of the player hirerchy?
probably pickupslot is the parent of the object you want to follow
Is it crucial that you set the position and rotation before setting the parent? You could set the parent then have localPosition
set to 0,0,0.
Your answer
Follow this Question
Related Questions
How to affect multiple rigidbodies with one box collider trigger? 1 Answer
Distribute terrain in zones 3 Answers
My Unity Collision Wont Trigger Even with Rigidbody Added 2 Answers
Ridgidbody cube 1 Answer
Multiple Cars not working 1 Answer