I have searched everywhere on this site looking for similar problems but couldn’t find any. After a couple days of trying to tinker with it I am coming to you guys for help because I can’t figure it out for the life of me.
The problem is that the bullet object for my character is instantiating at a random, set location away from the desired spot. See this picture → Imgur: The magic of the Internet
My original thought was that it was spawning at world coordinates instead of local, but I couldn’t get that to work. Next I figured my prefab have a wonky alignment, but after setting all of my prefab coordinates it still doesn’t work. Even hard coding in the coords still gave me the same result. This is also happening when I instantiate the enemy’s bullets, but I figure if I can get one fixed I can fix the other too
Here is the relevant code for my player controller…
And here is code for my bullet object
Note the comment which still always pops up with the proper coords despite spawning in a different location.
If anyone had some ideas I would be very appreciative
and if you are using “public Transform firePos;” then you have allready transform reference, so instead “firePos.transform.position” you can just use “firePos.position”. Use “firePos.transform.position” for GameObject like
“public GameObject firePos;”
I am sure, the solution is easy, but I cannot see it
Is the bullet builded from many object and the renderer is little offset ? Try place the bullet prefab in the scene and change its position to zero, then check if it is at zero point (place something other at zero, the camera as example, then it should be in middle of the camera). Or something is wrong with z-position and rotation.
That was it! I knew that the objects that made up the “bullet” objects had an offset, but I thought it was just so that they were spaced properly. Apparently not though! Thank you
And unfortunately still necroing posts because of it. Please, hit the like button if you wish to show your appreication, rather than simply necroing threads.
This isn’t even a 2D specific post. I’ll move it to the scripting forum.