- Home /
Physics.Raycast Interval problem in the FixedUpdate().
Hello. I'm making bullet system using Physics.Raycast.
Because my bullet is very fast. It moves 100unit per second.
I have a problem in my bullet system. Bullet doesn't hit object at certain distance.
example 
I shoot red point. Bullet doesn't hit dummy.
But I shoot the bullet green point. Bullet hit dummy.
  protected virtual void FixedUpdate()
         {
             if (m_IsFired == false)
                 return;
 
             // Projectile step per frame based on velocity and time.
             float stepLength = Time.fixedDeltaTime * velocity;
             Vector3 step = transform.forward * stepLength;
        
             Array.Clear(HitResults, 0, HitResults.Length);
 
             //Debug.DrawRay(transform.position, transform.forward * stepLength, Color.red, 3.0f);
             int HittedCount = Physics.RaycastNonAlloc(transform.position, transform.forward, HitResults, stepLength * RaycastAdvance, layerMask);
 
             IsDead = false;
 
             if (HittedCount > 0) // Hit!
             {
                 BulletHitHandling(HittedCount);
 
                 if (IsDead)
                 {
                     OnProjectileDestroy();
                 }
             }
 
             // Advances projectile forward
             transform.position += step;
             TraveledMeter += stepLength;
 
             if (TraveledMeter > EffectiveFireRange)
                 OnProjectileDestroy();           
         }
My Bullet code
Is there any solution of this problem?
Thank you for reading. I
I don't see any clear answer this second, but is there a reason to use your Raycast in FixedUpdate? FixedUpdate isn't guaranteed to be called every frame, and I consider raycast equivalent to input for the most part.
Your answer
 
 
             Follow this Question
Related Questions
Bullet collision for space shooter - colliders, rays, etc? 2 Answers
Random Raycast inside crosshairs 1 Answer
Bullet Trail Fade (Raycast) 2 Answers
Ray curve for bullet gravity effect, or any way to make it 1 Answer
Shoot with ray cast angle 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                