Question by
Andrew54321 · Dec 07, 2015 at 02:54 AM ·
rotate objectfixedjoint
Fixed object direction while another object is rotating
Hi,
I have two different object, pink and blue, and they are in hierarchy. As below.
When I rotate pink object, blue one would rotate at same time. However I need the blue one fixed in vertical direction, as figure in bottom right, instead of totally follow pink object. How to modify mine code? Hope someone could give me some suggestion! thanks
using UnityEngine;
using System.Collections;
public class FreezeMovement : MonoBehaviour
{
public bool FreezeZ = false;
private Vector3 OriginPos;
private Vector3 OriginAngle;
void Start ()
{
OriginPos = transform.position;
}
void Update ()
{
Vector3 currentPos = transform.position;
if(FreezeZ)
currentPos.z = OriginPos.z;
transform.position = currentPos;
}
}
rotate.png
(9.3 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612051637im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to set velocity from connected Rigidbody? 0 Answers
How to make object rotate on android platform 2 Answers
have one object rotate another object on the y axis 0 Answers
ScrollRect interferes with dragobject 0 Answers
is there a way to set a objects direction to a normalized direction. 0 Answers