Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Orloffyeah · Jul 09, 2014 at 06:14 PM · c#bulletshot

Bullets Shot Stay Still

Hi, I am passing an old shooting script that I made in JS to C#, and is working, except that the bullets just appear and aren't shot, where is my mistake? I know it worked almost a year ago.

Gun Script:

 using UnityEngine;
 using System.Collections;
 
 public class Shoot : MonoBehaviour {
 
 public float holdHeight= -0.5f;
 public float holdSide = 0.5f;
 public float racioHipHold = 1f;
 public float hipToAimSpeed = 0.1f;
 private float racioHipHoldV ;
 
 public float aimRacio = 0.4f;
 
 public float zoomAngle = 30f;
 public float fireSpeed = 15f;
 private float waitTilNextFire = 0f;
 public GameObject bullet;
 public GameObject bulletSpawn;
 
 public float shootAngleRandomizationAiming = 5f;
 public float shootAngleRandomizationNotAiming = 15f;
 
 public float recoilAmount = 0.5f;
 public float recoilRecoverTime= 0.2f;
 private float currentRecoilZPos;
 private float currentRecoilZPosV;
 public GameObject bulletSound;
 public GameObject muzzleFlash;
 public GameObject muzzleFlashSpawn;
 
 
 //Unlocks
 
 public bool weaponUnlocked = false;
 
  
 
     void Update () 
 
     {
 
         if (Input.GetButton("Fire1"))
         {
             if (waitTilNextFire <= 0)
             if (weaponUnlocked == true)
             {
                 GameObject holdSound = null;
                 GameObject holdMuzzleFlash = null;
                 
                 if (bullet)
                 {
                     Instantiate(bullet, bulletSpawn.transform.position, bulletSpawn.transform.rotation);
                 }                    
                 if (bulletSound)
                 {
                     holdSound = Instantiate(bulletSound, bulletSpawn.transform.position, bulletSpawn.transform.rotation) as GameObject;
                 }
                 if (muzzleFlash)
                 {
                     holdMuzzleFlash = Instantiate(muzzleFlash, muzzleFlashSpawn.transform.position, muzzleFlashSpawn.transform.rotation) as GameObject;
                 }
                 currentRecoilZPos -= recoilAmount;
 
                 waitTilNextFire = 1;
                 
                 if (holdSound)
                 {
                     holdSound.transform.parent = transform;
                 }
                 if (holdMuzzleFlash)
                 {
                     holdMuzzleFlash.transform.parent = transform;
                 }
             }
         }
 
         waitTilNextFire -= Time.deltaTime * fireSpeed;
 
         currentRecoilZPos = Mathf.SmoothDamp(currentRecoilZPos, 0f, ref currentRecoilZPosV, recoilRecoverTime);
     }
 }
Comment
Add comment · Show 3
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 DoctorWho · Jul 09, 2014 at 11:34 PM 1
Share

if you do not have a rigidbody attached to your bullet or created on the bullet, there is no way a force can be applied.

link to read unity manual, and have a sample code: click here

avatar image DoctorWho · Jul 09, 2014 at 11:37 PM 1
Share

not sure that link worked so here it is written out:http://docs.unity3d.com/ScriptReference/Rigidbody.AddForce.html or you can go to the scripting and type :Rigidbody.AddForce

avatar image vickygroups · Jul 10, 2014 at 04:03 AM 0
Share

agree with the above. add a script to your bullet that moves it. the easiest is with rigidbody.moveposition if you're using unity 4.5, but you can move an object without a rigidbody if you use vector3.lerp

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by robertbu · Jul 09, 2014 at 06:24 PM

There's no code here that moves the bullet. Should the bullet prefab have a script that moves it? If so, that would be the place to look for the problem. If not, you need to take a closer look at your translation.

Comment
Add comment · Show 1 · Share
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 Orloffyeah · Jul 10, 2014 at 03:45 AM 0
Share

Thanks man, I had a nother script which moved the bullet which I completely forgot about.

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

23 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

2d game facing bullets to mouse 2 Answers

what's the deal with the new (currently experimental) scripting system 0 Answers

C# Destroy tag on collision 1 Answer


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