- Home /
how to move a game object to another game object
im trying to add a head hitbox to my character, and how i want to do that is by moving a sphere collider where my camera is. but i dont know how im supposed to move the object. im thinking to get the vectors of the camera and just make the hitbox's vectors the same. but im not sure how to do that.
btw i edited the question cuz i copy, pasted it twice for some reason
Answer by pil95 · Mar 08, 2021 at 06:23 PM
Assuming you want the hitbox to be exactly where the camera is, you could just make the game object which contains the sphere collider a child of the camera. Then it should always be attached to it, no matter the camera's position.
im sure your way would work but how i have set my character up, i cannot do that. what ive done is set my camera to my character body, which means the parent is the character no matter what. so if i put on that game object, unity would just say its a child to a child of a parent. if i could do it, i would.
Okay another thing you can try in the script for the gameobject you want to move:
public Camera camera; //set this in inspector
Then inside the update method in the same script do
transform.position = camera.transform.position;
So it will update the gameobject position to that of you camera every frame
Your answer
Follow this Question
Related Questions
Get Object ID upon collision. 1 Answer
Set ContactFilter2d to not use child object's triggers. 2 Answers
Tilemap colision broked 0 Answers
Precise hitboxes for characters 1 Answer