in my current project the user can build a vehicle on block basis an attach weapons to it. Problem is: this way the weapons can turn in a direction where the projectile initializationpoint is inside other objects. Normally i wouldn’t care about it but whenever that happens the whole vehicle get’s teleported a small distance back and forth in one frame. The vehicles movement however is not distracted by it even though it’s physics based. All of said objects are parented below one center vehicle object.
So far im using a raycast to detect of the spawn is currently not inside a box to prevent the weapon from firing but this somehow does not help in every situation.
Is this by chance a problem of timing? I get the projectile from an object pool on mouseClick and set position and velocity as a direct result of the click. Might this be a problem since i tamper with Rigidbodys outside of the fixedUpdate funcion?
I’m happy about every Input i can get on this.
Let me know if you need more details on the project/problem.
Maybe, what you can do is to not instantiate the bullet at the front of the gun cannon, what you can dom is to instantiate them at some distance, always, and fill the “empy space” with a image or some kind of light /smoke efect.
This way, you dont even need to calaculate where is looking at, you know the bullet will spawn always correctly outside the vehicle.
Tell me if works!
You may want to look into Physics.IgnoreCollision() (or Physics2D.IgnoreCollision(), as applicable). Specifically noted on that (3D) page:
This is useful, say, for preventing
projectiles from colliding with the
object that fires them.
Thanks again for the input and the various creative answers. In the end it was easier to just relay on a layerbased aproach. Even though i have to relay on 3 Layers + Default and have to reset the layer of each projectile every time it is reused from the object pool it seems smoother and less performance heavy to me.
Sadly i still have to stick to the raycast from the bullets origin to see if the weapon is able to fire at all since i’d be able to shoot through my whole vehicle at any given time.