- Home /
object relative to another object, from its own position
So I'm trying to figure out how to have an object move relative to another object, but from its own position...I can do this by parenting, but I want the object to move half as much as the second object. Here's a simple code:
public Transform obj2;
void Update()
{
Vector3 newPosition = new Vector3(
obj2.transform.position.x * .5f,
obj2.transform.position.y * .5f,
obj2.transform.position.z * .5f);
transform.position = newPosition;
}
This code does some of what I'm trying to do, but I want the same behavior from the main object's original position... So that when I press play, it doesn't pop the main object to .5*position of object2, but just moves .5 as much when object2 moves... I hope this makes sense. I don't seem to be getting the right answers so if this doesn't make full sense please let me know. Thanks
Your answer
Follow this Question
Related Questions
Problem with making child an object 2 Answers
How to change game object's parent in hierarchy without changing it's transform's position? 1 Answer
Object with many children will not show up in the center although its coordinates are set to 0, 0, 0 1 Answer
Position of parent-Object 2 Answers
Setting parent in instantiated class 3 Answers