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 S.S.Q.R · May 31, 2013 at 07:29 AM · rigidbodyfpsshootingbullet

Issue with Bullet Movement shooting

Hi , After Hours Coding Finally i got the problem . The Bullet Not Moving in z Direction relative to Camera Z direction . i dont know what is supposed to be wrong with my code . I guess i did right way when make that script . Here is the code : ![alt text you can see my Bullet not Moving along z direction relative of Camera, but aside slightly . I dont know how to Fix it

     public class MenembakUjiCoba : MonoBehaviour {
        
         public float fireRate = 0.5f ;
         public float bulletSpeed = 100.0f;
         public WeaponType weaponType ;
         //public AudioSource source ;
         public float nextFire = 0.0f;
         public Vector3 posisiPeluru ;
         public Ray ray ;
         public RaycastHit hit ;
         // Use this for initialization
         void Start ()
         {
         weaponType = WeaponType.Automatic;
        
         }
        
         // Update is called once per frame
         void Update ()
         {
             if(Input.GetMouseButton(0))
             {
                 if(weapon == WeaponType.Automatic && nextFire < Time.time)
                 {
                     GameObject bullet = Instantiate((GameObject) Resources.Load("Bullet/bullet",typeof(GameObject)),PlaceInstantiate(),transform.rotation) as GameObject;
                     bullet.rigidbody.AddForce(transform.forward * bulletSpeed);
                     Debug.Log(Vector3.Dot(transform.forward,bullet.transform.TransformDirection(transform.forward)));
                     bullet.rigidbody.useGravity= false;
                     ray =new Ray(transform.forward,bullet.transform.forward);
                     if(pel.collider.Raycast(ray,out hit,0.0f))
                     {
                         if(hit.collider.CompareTag("Enemy"))
                         {
                             Debug.Log("Hit Musuh");
                             Destroy(pel);
                         }
                     }
                     nextFire = Time.time + fireRate;
                 }
             }
        
         }
        
         public enum WeaponType
         {
             Automatic=0,
             Manual=1
         }
        
         public Vector3 PlaceInstantiate()
         {
             return  Camera.main.ScreenToWorldPoint(new Vector3(Screen.width/2,Screen.height/2,Camera.main.nearClipPlane ));
         }
     }



 


error_peluru.png (445.8 kB)
Comment
Add comment · Show 4
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 bodec · May 31, 2013 at 07:35 AM 0
Share

is your editor set on global or local?

avatar image S.S.Q.R · May 31, 2013 at 07:40 AM 0
Share

Hi Thanks for Comment before :) I set my Editor on Global. In my First project i get seuccessfully to do that. I dont know what is the Problem

avatar image bodec · May 31, 2013 at 07:52 AM 0
Share

change transform.forward to vector3.forward im guessing im not sure I under stand the script you are using as the instantiate is nothing like I've seen before

avatar image S.S.Q.R · May 31, 2013 at 08:28 AM 0
Share

i change the transform.forward to be Vector3.forward . But the result is still same. About Instantiate , it just take Object from Assets folder and then Instantiate it in order the object could be seen in my scene. Thanks for your replies anyway ...after some hours someone reply my Thread , hahaha

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

14 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

Related Questions

Raycasr in my fps? 1 Answer

How do i adjust the projectile path and direction? 1 Answer

Rigidbody bullets won't spawn at gun barrel... 2 Answers

FPS rigidbody bullets not moving to center of screen 0 Answers

How to get bullets to hit crosshair 2 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