I want to put Sphere again and make it look like a bridge connecting Sphere like the top of the image with the thinned Cylinder in the center, so if you look at one Sphere in LookRotation, the Cylinder will not turn to the second and third (change the second argument to forward and right).By default, Cylinder is in the middle state.
Cylinder.transform.rotation=Quaternion.LookRotation (Sphere.position - Cylinder.transform.position);
One way to resolve this is to insert an empty game object into the hierarchy to correct the coordinate system.Here are two implementation examples:
+CylinderRoot...empty game object
+ Cylinder... Position(0,0,2) Rotation(90,0,0)
We use the simple LookAt() instruction in Transform to direct the target.
//at CylinderRoot
public Transform A;
public Transform B;
void Update()
{
transform.position = A.position;
transform.LookAt(B);
}
+CylinderRoot...empty game object
+ Cylinder... Rotation (90,0,0)
In this case, use LookRotation() because the direction is B as seen from A.
//at CylinderRoot
public Transform A;
public Transform B;
void Update()
{
transform.position = Vector3.Lerp(A.position, B.position, 0.5f);
transform.rotation=Quaternion.LookRotation(B.position-A.position);
}
621 Uncaught (inpromise) Error on Electron: An object could not be cloned
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
578 Understanding How to Configure Google API Key
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.