[Solved] Instantiated objects spawn at diferrent x
Hello, I'm building a simple game similar to Wolfenstein 3D. When I instantiate objects (bullets to specify) it has a right rotation, a right y and z positions but x is a little mystery to me. Sometimes it spawns in right x position, sometimes it offset in left or right but always this distance is the same. I'm confused what can be done wrong here. Below you can see code and information about GameObects etc.
public GameObject bullet;
public GameObject bulletSpawnPoint;
protected virtual void Shoot()
{
if (canShoot == true)
{
if (timerShoot <= 0)
{
Instantiate(bullet, bulletSpawnPoint.transform.position, bulletSpawnPoint.transform.rotation);
timerShoot = fireRate;
}
}
}
So as you can see it takes a position from bulletSpawnPoint and this bulletSpawnPoint is firePoint from this prefab. When I test it, it looks like fire point is always in a right position. I thought it can be something with the position of this fire point because it has positions like from the second screen but even when all coordinates are set to 0 this problem occurs.
If you have any idea what can cause the problem let me know because I'm clueless.
P.S. Hope my English is at least half decent.
try bulletspawnpoint.transform.localPosition and transform.localRotation
Tried it and this spawn bullets in one position in a good and bad way :). I mean it don't spawn bullets in three points but in one so this is little success but now this point isn't at end of weapon but fixed in ground.
Answer by NotEvenAverage · Apr 24, 2018 at 04:23 PM
Solution:
Now it works fine. I just locked xyz posiotions in rigidbody component in my Player prefab. The rotation was already locked because it was shaking for some reason but freezing position doesn't change movement in my case and fix this problem.
Your answer
Follow this Question
Related Questions
Create gameobject in other scene... 0 Answers
Unity won't Instantiate PLEASE HELP! 1 Answer
What is different when Instantiate set Prefab Position? 1 Answer
What is Casting in Unity ? 1 Answer