- Home /
shotgun like action
i got this code but all it does is drop the bullets on the ground! all the other guns work and thier code is
// Create the Bullet from the Bullet Prefab
var bulletPrefab = Instantiate(bullet, spawnLocation.transform.position, transform.rotation);
//source.Play();
bulletPrefab.AddComponent<TimeoutSpawn>();
// Add velocity to the bullet
bulletPrefab.GetComponent<Rigidbody>().velocity = -transform.forward * 18 * speed;
ammo--;
few lines down more i have (shotgun code)
//Shotgun movement
for (int i = 0; i <= Random.Range(1, 6); i++)
{
Vector3 shotgun = new Vector3(spawnLocation.transform.position.x, Random.Range(spawnLocation.transform.position.y - 30, spawnLocation.transform.position.y + 30), spawnLocation.transform.position.z);
var bulletPrefabshotgun = Instantiate(bullet, spawnLocation.transform.position, Quaternion.Euler(shotgun));
//source.Play();
bulletPrefabshotgun.GetComponent<Rigidbody>().velocity = -transform.forward * 18 * speed;
}
????????
is speed 0? Or -forward just bumping it into the gun killing the force?
Would have guessed the same. Another problem could be that if the bullets have actual colliders they collide with each other unless they are on a seperate layer the collision matrix disables collision between bullets which would be strongly recommended.
Answer by Rickasheye · Apr 20, 2018 at 08:18 AM
i have fixed this using Mathf.lerp and randomizing the rotation
Your answer
Follow this Question
Related Questions
How do I fix collisions while using this PlayerController script? 1 Answer
How to move the character with the current? 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Only make a timer work while an object has velocity 1 Answer
FPSController camera moving into model when any button to move the character is pressed? (WASD) 0 Answers