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 Tony 5 · May 17, 2011 at 04:56 PM · transformdirectionshootaim

Bullet shots direction player is facing, cant shoot in diagnal or up

hi, here is my bullet script

var Bullet : Transform; var ROF = 10.0; // Rate of fire in bullets/sec. private var timeout = 0.0;

function Update () { if (Input.GetButton ("Fire1") && Time.time >= timeout){ var bullet = Instantiate(Bullet,GameObject.Find("BulletSpawn").transform.position,Quaternion.identity); bullet.rigidbody.AddForce(transform.forward *1000); Destroy(bullet.gameObject, 2); timeout = Time.time + 1.0/ROF; } }

when I shoot, it will shoot the direction that im facing. so i can do a compleat circle and shoot fine. but when I shoot at an upward angle, the bullets go parallel to the ground. what should i do. i also get a error message saying

UnassignedReferenceExceprion: The variable Bullet of 'Shooting script' has not been assigned. but in the inspector, it is assigned. thanks for your time

Comment
Add comment · Show 2
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 flaviusxvii · May 17, 2011 at 04:59 PM 1
Share

Please format your code properly. Use the "10101" button.

avatar image flaviusxvii · May 17, 2011 at 05:01 PM 0
Share

When you say "shoot up" are you talking about positioning the mouse in the upper half of the screen when you click? The mouse position is NOT related to transform.forward on whichever GameObject this script gets attached to.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Fabkins · May 17, 2011 at 05:26 PM

I assume "BulletSpawn" is at the end of your gun. If "BulletSpawn" is attached to character that is animated then I would expect this to work.

If however "BulletSpawn" is just a fixed position against the the player controller then it will fire at the same plane as the player controller.

I guess a quick experiment would be to replace "BulletSpawn" to whatever the camera is called. In theory then you should fire in the same direction that you are viewing.

Not an expert so appologies if this answer is incorrect but something to try.

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 Ninjaoboy · Jun 24, 2011 at 06:57 PM

is the spawn attached to your camera so that if you look up the spawn will be there too.

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

1 Person is following this question.

avatar image

Related Questions

Shoot second cell in 2d 0 Answers

Animation Play On Bullet Shot 1 Answer

Problem with child position 0 Answers

Converting Direction Vectors In Children Manually 0 Answers

Object hold and mouse roll 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