c# How to scale a game object using another (non-parent) object as pivot
So I have a script that scales SteamVR CameraRig up and down:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class C_Pivot : MonoBehaviour {
public GameObject target;
public GameObject cameraRig;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.position = new Vector3(target.transform.position.x, cameraRig.transform.position.y, target.transform.position.z);
}
}
But it can only pivot from the center of the rig regardless of where the "head" is. I want the scale to pivot from another game object let's call it "pivot" that follows the "head" on x and z but sticks to the CameraRig's y which is the ground:
pivot.transform.position = new Vector3(head.transform.position.x, cameraRig.transform.position.y, head.transform.position.z);
Problem is, I cannot parent the CameraRig to a pivot object for various reasons. It would be ideal for me if I can make any game object the pivot.
Thanks in advance for any suggestions.
did you love your question? I need to change position of object only one side with other object. can you help me in this please
Answer by PlexusDuMenton · May 28, 2017 at 08:05 AM
the easier way would be to define the pivot directly from the 3D software (like maya , blender or 3DSMax)
Your answer
Follow this Question
Related Questions
[HELP][SCALE] localScale doesn't follow the object's pivot 1 Answer
Sprites and Shaders : problem with lighting 2 Answers
Mirroring a gameObject 0 Answers
Manipulating Objects in callback 0 Answers