HELP: Need framedrop reduction with bullets!

Hi there!,

I have a question, and I hope some people can give me some advice.

I’m working on a side-scrolling shooter >>HERE<<
First the bullets went trough enemies. I looked up a script that could fix that.
What I found was a script that creates a raycast between the position in the last frame and the position in the new frame to see what it has missed.
But, if you fire a lot of bullets the frame rate drops.

Does anyone have a suggestion to fix this in a ‘cheaper’ way so my frame rate doesn’t drop so much?

Optimization is probably the area where a clear definition of your implementation details is required the most. Helpful information:

What does your bullet firing code look like?

How are the bullet scripts structured?

What is this script stopping the bullets from going through things?

Ah and your site seems to be having some problems. The page shows up with a “missing plugin” message - even though I do have a fresh install of the 3.4 plugin.

This is a script I found on the Wiki merged with my own stuff for the bullets/projectiles.
(I have to state that I don’t have a frame drop, but I had complaints about them)

using UnityEngine;
using System.Collections;

public class projectiles : MonoBehaviour {

	public float fireSpeed = 4f;
	public float lifeTime = 50;
	public float spray = 2F;
	
	public GameObject Player,Enemy,Controller;
	
	public LayerMask layerMask; //make sure we aren't in this layer 
    public float skinWidth = 0.1f; //probably doesn't need to be changed 
    
    private float minimumExtent; 
    private float partialExtent; 
    private float sqrMinimumExtent; 
    private Vector3 previousPosition; 
    private Rigidbody myRigidbody;
	
	// Use this for initialization
	//initialize values 
    void Awake() 
    { 
       myRigidbody = rigidbody; 
       previousPosition = myRigidbody.position; 
       minimumExtent = Mathf.Min(Mathf.Min(collider.bounds.extents.x, collider.bounds.extents.y), collider.bounds.extents.z); 
       partialExtent = minimumExtent * (1.0f - skinWidth); 
       sqrMinimumExtent = minimumExtent * minimumExtent; 
		transform.eulerAngles = new Vector3(transform.eulerAngles.x,transform.eulerAngles.y,transform.eulerAngles.z+Random.Range(spray,-spray));
    } 
	
	// Update is called once per frame
	void Update () {
		transform.Translate(-Vector3.right*fireSpeed);
		
		if(lifeTime<=0){ Destroy(gameObject); }else{ lifeTime--;};
		
	}

	void FixedUpdate() 
    { 
       //have we moved more than our minimum extent? 
       Vector3 movementThisStep = myRigidbody.position - previousPosition; 
       float movementSqrMagnitude = movementThisStep.sqrMagnitude;
        
       if (movementSqrMagnitude > sqrMinimumExtent) 
        { 
          float movementMagnitude = Mathf.Sqrt(movementSqrMagnitude);
          RaycastHit hitInfo; 
            
          //check for obstructions we might have missed 
          if (Physics.Raycast(previousPosition, movementThisStep, out hitInfo, movementMagnitude, layerMask.value)) {
             myRigidbody.position = hitInfo.point - (movementThisStep/movementMagnitude)*partialExtent;
			Debug.Log(hitInfo);
			}
       } 
        
       previousPosition = myRigidbody.position; 
    }
}

And about my website’s player, weird, I can play it… Could it be that I’m not building it in the latest version of unity?

Ow, I think I found a problem…
I forgot to destroy the bullet when it hits…

Have you tried using the Continuous Dynamic setting for collision ? And if they still pass through try changing the Timestep in the TimeManager?

(without the extra code you have added)

Continuous Dynamic didn’t work, I’ve tried that… but the Timestep sounds like a good idea.
Thank you for the suggestion.

I still have a lot to learn!