- Home /
The question is answered, right answer was accepted
Object positioned at wrong location
i have a very simple scene which has a sphere and a cube. All i am trying to do is set the location of the cube always behind the sphere at a certain defined distance(i defined a variable distanceaway in the script for setting this distance). OUTPUT: the cube is not put at the location i expected and no matter what the value of the variable distanceaway is set the cube's location is unaltered.(i attached an image of the ouput where i circled the cubes position in playmode). The script is attached to the sphere and takes the Transform of the cube as an input.
Answer by Patrickmol · Jun 16, 2021 at 06:48 AM
I would guess (didnt test it)
Cube.postion = transform.position + (transform.forward * distanceaway);
It's pretty hard to hit those things, you have to stop and think about it... Like you have to imagine the calculation... you have the sphere position and you want to add something to it if you normalized the position it will return a number like 39 and that's not a vector actually so you have to use a vector position and add something to it and here we go :) Happy that I helped you!
Follow this Question
Related Questions
Rotate AI towards nearest target within sphere collider 2 Answers
Does it help performance to first check if some transform attribute has changed before setting it? 1 Answer
Colliders vs Transform Position for performance 3 Answers
My object is translating with speed but does not stop... 1 Answer
Trying to position a world space menu in front of the camera whilst ignoring the camera's tilt angle 1 Answer