- Home /
The question is answered, right answer was accepted
Moving an object with dependency of it's rotation
Hi guys,
So I'm spawning objects in a circle and want to move them further away from the middle point of the circle. Every object is facing a specific direction (away from the middle point). Now I want to increase the diameter of the circle by moving all objects away from the middle point (in the direction they are facing)
I tried Vector.up but that was obviously not working... So I tried Vector3.up with localPosition but that wasn't working either. Do you have any suggestions what to use? I stumbled across Transform.InverseTransformVector and Transform.TransformDirection.
They sound pretty good but I have no clue how to use them. Does anyone have an idea?
BTW: I don't want finished copy-paste code. I want to understand this s$$t ;) so I can use it myself in other projects :)
Thanks for your help.
Answer by dishant27 · Feb 28, 2018 at 07:18 PM
Firstly, create a circle equation keeping center = middle point and radius = distance from the middle point. Now from that equation define x in terms of y say f(y) or y in terms of x say f(x). It's your choice to use either (f(y), y) or (x, f(x)); I'm explaining using (x,f(x)). Now, Instantiate at objects on that circle by providing any x value on that circle and f(x) will decide the corresponding value of y. By varying the value of x, you can spawn objects on that circle at different positions. Make each object face to the center by using Unity's LookAt() method. Now, transform using localPosition axis(facing towards center) to move away from the center.
Hmm I think I didn't explain it really well. I have 40 spawnpoints in shape of a circle. I have already instantiated an object at a random point. $$anonymous$$y problem is that i have different things to spawn with diffrent hights. So I want to move them up or down by half their size.
Now it's more confusing. In question, you are saying "increase the diameter of the circle by moving all objects away from the middle point". But in comment, you are saying "move them up or down by half their size."
Well I thought that would make it easier to explain. When you can imagine a circle.... Whatever. Sorry if my original question was misleading. $$anonymous$$y original question should be "How can I move an instanciated obejct relative to its rotation" :)
Follow this Question
Related Questions
Bouncing Ball Problem( bounces vertically forever) 1 Answer
[JS] transform.rotation not working 1 Answer
Quaternion rotation with normals bug: Only works into one direction? 1 Answer
rotation relative to a transform 1 Answer
How to rotate instantated prefab without rotating it's local directions by javascript? 1 Answer