0
\$\begingroup\$

I created a flask and added a fluid stream to the top of the flask. When I translate the flask, the fluid stream goes along with the top of the flask. How do I achieve this when rotation occurs.

   void Start () {
    aa.transform.position = new Vector3(bb.transform.position.x, 
    bb.transform.position.y + 4, bb.transform.position.z);
    aa.SetActive(false);
    aa.SetActive(true);
   }



void Update () {
    aa.transform.position = new Vector3(bb.transform.position.x, bb.transform.position.y+4, bb.transform.position.z);
   //aa is the fluid stream and bb is the flask
    cc.transform.position = new Vector3(bb.transform.position.x, bb.transform.position.y + 4, bb.transform.position.z);
    }

The traslation works. But you can see the gap between top of flask and rotation here. How do I close that gap?

The traslation works. But you can see the gap between top of flask and rotation here. How do I close that gap?

\$\endgroup\$
1
\$\begingroup\$
// The flask we want to attach to.
public Transform flask;

// The stream object (assuming the liquid flows from its local origin)
public Transform stream;

// Position of the spout in the flask's local space.
public Vector3 spout;

// By running in LateUpdate, we ensure the flask has had a chance to move 
// already this frame, before we try to follow it.
void LateUpdate() {
    // Set our stream's origin to the position of the spout after applying
    // the flask's transformation (including translation, rotation, and scale).
    stream.transform.position = flask.TransformPoint(spout);
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.