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 ryanjuk · Nov 13, 2014 at 05:07 AM · instantiatebullettransform.forward

Fire bullet in camera direction problem

So I've been at it for 3 hours and have made no progress. For some reason my bullets don't properly respond to the Y axis of my camera. Image below and my code to help explain.

alt text

     void shoot() {
         NetworkViewID viewId = Network.AllocateViewID ();
         networkView.RPC ("spawnBullet", RPCMode.AllBuffered, viewId, Camera.main.transform.position, Camera.main.transform.rotation);
     }
 
 
     [RPC]
     void spawnBullet(NetworkViewID viewId, Vector3 bulletPos, Quaternion bulletRot) {
         bullet = Resources.Load ("bullet");
         GameObject myBullet = (GameObject)Instantiate(bullet,bulletPos,bulletRot); 
         NetworkView nView = myBullet.GetComponent<NetworkView> ();
         nView.viewID = viewId;
         print ("bulFor: "+myBullet.transform.forward);
         myBullet.rigidbody.velocity = myBullet.transform.forward * 80f;
     }

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by IEMatrixGuy · Nov 13, 2014 at 05:35 AM

Hi,

You are using 'bulletPos' as a transform here, are you sure that this position is assigned to the correct place?

The way I personally would go about implementing this, would simply be to use Camera.main (assuming you are using the main camera) or playerCam (some camera variable that points to your players camera) transform.position & transform.rotation.

This should in theory mean that it would be instantiated exactly in the middle of the camera, which is where you are aiming from...

Hope that helps :)

Good luck,

IEMatrixGuy

Comment
Add comment · 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
0

Answer by ryanjuk · Nov 13, 2014 at 06:50 AM

bulletPos & bulletRot are "Camera.main.transform.position, Camera.main.transform.rotation" as defined in the network rpc call.

I found an answer though. The bullets are travelling too fast for the physics engine. I had to up the timestep significantly for it to work. So will need to take a look at the performance hit and work out whether to work out another way or not.

Comment
Add comment · 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
0

Answer by AngryBurritoCoder · Nov 13, 2014 at 11:25 AM

Whats your bullet force, and if it is travelling too fast, you may want to use the Check collision script found on unity wiki, allows you to check rigidbody collisions using a script and works perfectly with huge forces

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Everytime I Instantiate, object becomes smaller. 2 Answers

bullet issue 3 Answers

Bullet stops when new bullet instantiates pls help 3 Answers

Modify the rotation of Instatiate prefab 1 Answer

Best way to make bullets? 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