How can I make an object follow another, like they were parented

It’s easy enough to get one object to follow another’ position and rotation. My problem is that I don’t know how to keep an offset in the way I want. I have an object attached to my player, and when the player turns around (FPS controls) I want an object to follow the player around like it was parented. But the way I’m doing it now, means the object doesn’t follow the position change when the character rotates, it only rotates around itself, not the player. I want the object to “rotate around” the player. I’ve attached an image for clarification.

I assume you have some sort of positional offset defined in your code. If you want this positional offset to rotate with the ‘parent’ object, you could do something like this

public Vector3 normalPositionOffset;
public Transform parent;

void Update(){
    Vector3 rotatedOffset = parent.rotation * normalPositionOffset; //Rotates the offset vector by the parent's rotation
    transform.position = parent.transform.position + rotatedOffset;

The easiest way would be to just parent it, you can set the parent like this: transform.Parent=otherTransform. You can set it to null to unparent it as well. You can also use a hinge, or you could write a script so that it moves with your character and when your character rotates you have to rotate it around your character.

This code calculates the relative position/rotation at the Start() and moves/rotates the child object accordingly:

public Transform _child;

private Vector3 _childRelativePos;
private Quaternion _childInitialRot;

void Start () {
	_childInitialRot = _child.rotation;
	_childRelativePos = _child.position - transform.position;

void Update () {
	_child.position = transform.rotation * _childRelativePos;
	_child.rotation = _childInitialRot * transform.rotation;