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 futureseeker 1 · Feb 17, 2011 at 07:35 PM · bulletcenter

Bullet shots isn't in the center

I have a a bullet prefab, rigid body added, with 0.1 mass, use gravity checked. and i have a cross hair at the center of the screen. My prob is that, it doesn't shoot in the middle of the crosshair, it's slightly shooting around a few cm to the left of the crosshair.

I also had locked the cursor, but it didn't fixed the problem. How can i shoot in the middle?Do i need to adjust the mass?the force or something?

here is my code for shooting:

var projectile: Rigidbody;

function Update () { if(Input.GetButtonDown("Fire1")) { var instantiatedProjectile:Rigidbody=Instantiate(projectile,transform.position,transform.rotation); instantiatedProjectile.velocity=transform.TransformDirection(Vector3(0,0,50)); Physics.IgnoreCollision(instantiatedProjectile.collider,transform.root.collider); }

}

Thanks!

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 Peter G · Feb 17, 2011 at 09:42 PM

If you are shooting your projectile out of a gun, then more than likely you have rotated the gun slightly off center with the 1st person controller. Then, since you are launching the bullet in the same direction, it will be slightly askew from the forward vector of the camera so it will fly in a slightly off direction.

The easiest way to fix that would be to reset your gun's y euler rotation or to give the projectile its direction from something else.

    var instantiatedProjectile : Rigidbody = Instantiate(projectile,transform.position,transform.root.rotation);
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 futureseeker 1 · Feb 18, 2011 at 02:35 PM 0
Share

hi, i tried replacing the var instantiatedProjectile in my code with yours, but it didn't fixed the prob. The bullet is still not in the center.did i replaced the code the wrong way?i hope there's still a way.

avatar image
0

Answer by CommitteeWind · Mar 17, 2011 at 11:32 PM

instantiatedProjectile.velocity=transform.TransformDirection(Vector3(0,0,50));

That line of code is your problem. Try multiplying some Speed * transform.forward; Also, if you find that your rotation isn't what you're wanting then use:

Camera.main.transform.rotation

Instead of

transform.rotation
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 Peter G · Mar 17, 2011 at 11:34 PM 0
Share

Not quite. The top line is the same as transform.forward * 50;

avatar image
0

Answer by jamie1 · Nov 17, 2011 at 07:05 AM

hey im have a similar problem, well i have my gun and the spwan point for the bullit right in front of the nozzle (tip) and it shoots fine except if you watch the bullit travel it flys and then is almost pulled to the floor almost as if the bullet is magnetically attracted to the floor, so if i aim up woods the bullet flys straight for the ground. ANy thoughts ???

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 syclamoth · Nov 17, 2011 at 07:06 AM 0
Share

Please post a new question, ins$$anonymous$$d of posting useless copypasta 'answers' to different questions.

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

2 People are following this question.

avatar image avatar image

Related Questions

Guns don't shoot straight. 3 Answers

Bullet Collision Simulation? 2 Answers

Raycasr in my fps? 1 Answer

rigidbody' is not a member of 'UnityEngine.Object 1 Answer

Bullet Problem 0 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