Inconsistent position after setting parent

Hi,guys

I imitated the example of the official document and tried to make a luminous street lamp. I created a SpotLight, set diffuse to yellow, and set its parent to the light bulb “Mesh03_primitive0”. But it turns out that SpotLight is not in the position of Mesh03_primitive0 (but moving Mesh03_primitive0, SpotLight can move together), and when I turn off other lights in the scene, SpotLight does not light up.

So,what can I do to fix it?

image

well, I found that SpotLight did illuminate, but it was very weak.

What confuses me is that the position of SpotLight is not in the center of the parent.

lampLight.position = scene.getMeshByName("Mesh03_primitive0").position;

Parenting and positioning are just 2 different things.

1 Like

Thank you, but sorry it doesn’t work. If I just set the position of lampLight, it will be at the origin of the world coordinates. If I set parent and position at the same time, there will be the same error as before.

It is in the origin because you created it in this position.
!.position as in your screenshot will not work, seems it is the typo.

1 Like

I’m using typescript in my project, when I use the position property directly, error shows:

image

So In have to add ! operator to ensure that the “position” property does exist.

This is the information of Mesh03_primitive0, which is the bulb in the street light

image

and it’s parent information is:
image

I really don’t know what went wrong :cold_sweat:

In this case you can make it even simpler, just pass the right position as new Vector3 object when creating the lampLight.

1 Like

Yes, I have tried it. When I create the lampLight using the position of “Mesh03_primitive0”, it is still at the origin of the world coordinates.

The position of “Mesh03_primitive0” relative to its parent “Mesh03” is (0,0,0), but lampLight seems to treat it as (0,0,0) of world coordinates, so it is located at the origin of world coordinates after creation, rather than where “Mesh03_primitive0” actually locates.

In the Inspector - move the lampLight with gizmo to the needed position, so you’ll find the right values for your case.

1 Like

I tried this at the very beginning, but the process of moving was very difficult. Under the camera’s perspective, it was always impossible to move to the correct position. From one angle, the position seemd to be correct, but from another, there existed deviation.

image

Is there any way, like in 3dsmax, to observe objects from the top, left, front and other positive directions? In that case it will help me adjust the position of the object.

From the information from the screenshots I assume that X and Z positions will be the same as with Mesh03, so you’ll need only to adjust Y value.

1 Like

Thank you, I already know where the problem is. When I went back to 3dsmax to view the model, I found that the pivot of the object “Mesh03_primitive0” was at the bottom, so the lampLight would be at this position, and it could be solved by adjusting the pivot to the center of “Mesh03_primitive0”.

image

image