- Home /
Other
Bullets don't always appear at spawn point
Hi,
Thanks for reading. Having some difficulty with bullets in my game. Sometimes, when they are first visible, it is some distance from their spawn point. Bullets have a rigidbody and are moved with this code (in Update method):
transform.Translate(0, 0, bulletSpeed * Time.deltaTime);
transform.position = new Vector3(transform.position.x, 0 , transform.position.z);
Bullets ignore collisions on the player layer. If you need anymore info, let me know.
Update 1: This problem doesn't seem to occur in the build, only when the game is played within Unity.
Tried so far:
There were quite a lot of fields to set (various bullet stats). Commented out the code for setting these, incase it was causing a delay. Also got rid of trail renderer
Checked for any collisions that might be happening as the bullet is spawned. Doesn't seem to be anything.
Moved the spawn points to see if that changed anything
Open to suggestions on fixing this. Worse case scenario, I can use the muzzle flare graphic to disguise the problem, but I'm a little concerned this may be the symptom of another problem.
Any chance one bullet is colliding with another at the spawn point?
There's a fairly decent $$anonymous$$imum interval between bullets, so that's unlikely. I found that it only happens when the game is played in the editor, not in the build, so I guess it's not really a problem anymore.
I'm going to close off the question, but would you know why different things are happening in the standalone build and the editor? Is there much of a processing overhead when playing the game in the editor?
A rigidbody using Translate to move? Is the rigidbody always set kinematic (so, only used for collisions?)
Running in the editor has a few rare glitches that won't be there for real, and can sometimes have rare stutters while it manages editor data, but you'd be seeing it for everything -- not just the bullets.
transform.Translate(0, 0, bulletSpeed * Time.deltaTime);
transform.position = new Vector3(transform.position.x, 0 , transform.position.z);
If the code is in Update then you are applying 2 different movement methods and neither of them will work well with physics. You are teleporting twice a frame. Once forward, once on the spot but at world y = 0.
If they have rigidbody use AddForce or $$anonymous$$ovePosition. There are verious raycast methods, too.
If they have rigidbody use AddForce or $$anonymous$$ovePosition.
If for some reason you need to zero world y axis, try to do it once at the start (on instantiate?) and then have just one movement call routine. Your bullet is kinda flickering through space.
Follow this Question
Related Questions
Shoot Bullet Delay Enemy 0 Answers
Classic Fireball Shooting Up Obstacle 1 Answer
Bullet spawning to low.. 0 Answers
Problem with enemy shooting 4 Answers
Spawn an object? 2 Answers