No worries. I guess the problem might be with how I can’t get the position on my player, so I can then subtract a distance between my player’s y axis, and the prefab I want to spawn.
I just copied your code and tried it. I substituted ‘PlayerControl’ for just a transform of a Sprite, obviously because I don’t have that file/code.
All of my obstacle objects spawned at the same height (which was what I set … subtracted from the player’s position.y).
Not one of them spawned at any other height, or higher than the player.
This leads me to ask if the Obstacles have any height already set on them before you instantiate them (ie: in their prefabs maybe).
Ok, your code is correct. Just out of curiousity, what are the Y values on the prefabs, and what is the distance you use (set in the inspector) for “below the player” ?
I think I got what your saying. I didn’t reset the positions on the prefab. My prefabs has parent/child. I already reset the position for all the parent. I can’t reset the position for the children since I need their position to be the obstacle. <-Will this cause a problem?
Well, I cannot really say 100% because I’d just be guessing as to how you have it setup.
Let me say what I was thinking and you can take it from there…
If you had +5 to the y position on a prefab., and a minus 4 on how far below you want to spawn the object, let’s say…
then when you spawn -4 + 5 you get 1 Which is … (obviously) 1 above your player… and so on.
There’s no problem, so long as you keep that in mind, and adjust/set accordingly
AWESOME MAN! You just solved the problem, I was messing around with the code when the problem is with the setting of the prefab. It’s working good now. I didn’t reset the X value of the children, I just set their Y’s to 0. Here’s how the spawn looks like: