I have a simple question that somehow i cannot figuring.
It just a simple Unity cube and sphere. Nothing fancy.
Currently if i rotate the bigger cube in X, Y and Z, of course the yellow sphere will follow.
because it is a child of the bigger cube like this;
But what I would like to have is; to make the yellow sphere stay in place, when the bigger cube is rotating in X axis; like this:
I do want to keep the Child's transformation when the bigger cube is rotating in Y and Z though. Like this one;
I use Transform.TransformPoint. But still no luck.
I do attached this script to the Yellow Sphere., It holds yellow sphere but also holding its position when the Bigger cube is rotating in Y&Z(which i dont want too).
public class lockedPosition : MonoBehaviour
{
public Transform target;
private Vector3 debug;
public Vector3 offset;
// Start is called before the first frame update
void Start()
{
debug = transform.position;
}
// Update is called once per frame
void Update()
{
this.transform.position = debug offset;
}
}
any pointer on this will be awesome! :D
Thankss!! ^^,
CodePudding user response:
you can checkout this answer. I hope this might be able to do the trick for you. You can maybe use the transform.rotation.x or something to hold your child objects position while the parent is rotating in x axis. I hope this works out for you. Happy coding :)