- Home /
A problem with bullet speed on different computers.
I have a strange problem with the speed of projectiles shot by a weapon. On various operating systems and hardware configs the speed is different, however is doesn't seem to have anything to do with the configuration, for example on core i7 3770k / 8GB RAM / GF 660Ti / SSD / Windows 7 64bit the speed is identical as on core i3 4000m / 4GB RAM / Intel HD 4600 / HDD / Ubuntu 14.04.1 64bit, but on some configs the bullets are a lot slower or even the speed of the projectiles varies (every fourth shot a faster bullet is spawned). I have no idea why is this happening, but I tried some advices I've found on this forums like multiplying by Time.deltaTime. It didn't make a difference. Does anyone know how to resolve this?
I'm providing some excerpts from my code below.
void Update () {
if (Input.GetButtonDown("Fire")) {
Shoot();
}
}
void Shoot() {
Rigidbody newBullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation) as Rigidbody;
newBullet.rigidbody.AddForce(Vector3.right.normalized * power * Time.deltaTime);
}
Answer by tanoshimi · Jan 31, 2015 at 11:26 PM
Remove Time.deltaTime from your AddForce equation - it makes no sense to include it there. (Why would the force at which a bullet is fired depend on how long it took to render the last frame?)
Thank you. I apparently used two fixes at once and accidently didn't fix the problem. Removing Time.deltaTime did indeed work :)