Vector3 with two set axis but one free one
I just started coding so I'm a bit confused and I'm also not quite sure how to explain my problem But here we go:
So I want an gameobject1 that is on top of gameobject2. I want the gameobject1 to be on the same x and z axis with the gameobject2, but have its own y axis. I can't figure a way to do this.
I've tried with Vector3 but either the gameobject1's y axis is frozen in place and cannot be moved or it doesn't follow the gameobject2's x and z axis.
I would really appreciate any help.
Answer by Bunny83 · Dec 06, 2019 at 03:15 AM
Well you just have to replace the y component of your temporary vector with your current y value.
Transform gameobject1;
Transform gameobject2;
Vector3 pos = gameobject2.position;
pos.y = gameobject1.position.y;
gameobject1.position = pos;
I've tried similiar things but like this one It doen't work in the way I would like because I need the y axis to follow gravity.
What do you mean, "follow gravity" ? Are you free object and restrained object rigidbodies? What effect do you want to achieve?
I mean that it could move freely up and fall down with gravity but it would follow the other gameobject's x and z axis. I don't know any better ways to describe my problem.
Your answer
Follow this Question
Related Questions
Hold mouse to move camera doesn't work 0 Answers
CAMERAS ERROR , I NEED HELP 0 Answers
Script to random set active a child object? 0 Answers
Scripting - need help to make my script shorter 1 Answer
How can I replace objects in the initial position? 0 Answers