- Home /
Objects not always Spawning At Correct Location
Using the Basic function for instantiating, (GO, v3, quaterion) bullets, sometimes but not always my bullets will be spawned a few units right or left with different rotation than intended. Previously I've never had this issue, the only difference is now I'm using a terrain but that shouldn't affect spawning locations of bullets.
Side Note: The faster the bullets the more profound the effect is
yeah, I have the same issue. For my "bullets" I am just spawning bulletholes where a raytrace hits so can't tell if they are "off" or not, but when I tried instantiating tracers for a visual effect I have the same issue where the source is either left or right of my gun barrel. $$anonymous$$y only guess being that a terrain slows the frame rate enough to lag the instantiation. Probably not but that is all i can think of
i dont think its FPS related becuase im getting over 500 frames while in my project
Answer by Bleakmountain50 · Apr 15, 2018 at 11:01 PM
make a public gameobject called target then put this in where ever it spawns the object transform.position = target.transform.position; make sure that "target" is a gameobject thats at the place you want the bullet to spawn
that is what I do ...it's not that the bullets ( or in my case, the tracers) aren't spawning at the muzzle location because if I am not moving my gun they look fine. It's only when I am moving the gun around ( it's a turret gun) do the tracer spawns seem to lag a frame or two behind the gun movement. Target is a child of the gun so it is also moving with the gun. I kind of think I know the problem is in that the gun script ( from store) uses LateUpdate to fire bullets ( the sound of gunshot is called there so I figure so is everything else fro firing and that is where the instantiate tracers is called.) while the turret movement is in the update function. Think that is the cause for the visual lag?
I do have a "BulletSpawner" GO, at the end of my muzzle but still no luck. I just dont understand why the objects are not spawning at BulletSpawner.position and BulletSpawner.rotation. In past projects I've never had an issue with this.
just to double check.... because I made this mistake before - I didn't take the collider component off the the bulletspawner GO and my bullets had RB on them so the collider messed up the instantiated bullet
Yeah i know what you mean but my Spawners are clean nothing but Transform
Answer by Firas4d · Apr 16, 2018 at 07:05 AM
Hi, do the bullets have colliders/rigidbodies attached to them? if so, then each time 2 bullets get instantiated at the same place, one of them may move according to the physics engine calculations. Using physics layer mask will solve your problem.