Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by yerdna12 · Sep 21, 2016 at 12:12 AM · vector3velocityforward

My bullets don't fire properly

I am making a first person shooter in 3d, and I made a gun and bullets, but when i fire, the bullets glitch out. For some reason, when I am firing straight, the bullets fly normally, but when I fire up, the bullets first fly normally, and when they get a certain distance away, they change directions and start going down. Here is my code for the gun, which fires the bullets: using UnityEngine; using System.Collections;

public class AK47 : MonoBehaviour {

public GameObject bullet; public GameObject bulletEmitter; public float bulletSpeed = 10; private float duration = 0.2f; private float nextFire; private int bulletsFired = 0; private Animator animator; private Rigidbody rg; private bool reloading; public AudioSource[] aSources; private bool firing = false; public GameObject gunFiring; public GameObject crosshairImage; public float speed = 50; public GameObject zombie; private EnemyHealth hlth; private float yRot; private float zRot; private float xRot;

public Camera camera;

//Usethisfor initialization void Start () {

animator = GetComponent(); gunFiring.SetActive(false);

}

//Updateiscalledonceper frame void Update () {

//this.transform.rotation=camera.transform.rotation;

if (bulletsFired == 25 || Input.GetKeyDown(KeyCode.R)) {

gunFiring.SetActive(false); firing = false; animator.SetTrigger("ReloadTrigger"); aSources[0].Play(); bulletsFired = 0;

} if (Input.GetMouseButton(1)&& Time.time > nextFire && reloading == false) { nextFire = Time.time + duration; Fire(transform.forward* bulletSpeed); bulletsFired += 1; firing = true;

}

if (Input.GetMouseButtonUp(1)) { firing = false; gunFiring.SetActive(false); }

}

public void Fire (Vector3 velocity) {

GameObject bulletClone = (GameObject)Instantiate(bullet, bulletEmitter.transform.position, Quaternion.identity) as GameObject; //rg.velocity=bulletEmitter.transform.forward*bulletSpeed; rg = bulletClone.GetComponent(); rg.velocity = velocity; gunFiring.SetActive(true); //animator.SetTrigger("RecoilTrigger");

}

public void SetReloading() { reloading = true; firing = false; } public void ReloadingOver() { reloading = false; firing = true; } void PlayGunFire() { aSources[1].Play(); } } What is the problem and how could i possibly fix this?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image lawrence-parry · Sep 21, 2016 at 09:11 AM 0
Share

Use the 101 button to add code to you question correctly, this might increase the likelihood of it getting answered.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

78 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rigidbody velocity forward is Camera forward 1 Answer

Set the Velocity to reach a position at a specific Timestamp 0 Answers

Slow down a character while they are midair while keeping their original velocity 0 Answers

Speed limit to AddForce (without limiting velocity of rigidbody) 0 Answers

How can I make my player jump faster but not higher? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges