Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Dec 27, 2016 at 06:13 PM by raulismasiukas for the following reason:

User error.

avatar image
0
Question by raulismasiukas · Dec 27, 2016 at 05:40 PM · rigidbodyvector3forceprojectile

Issue with shooting projectiles in the direction of the arrow keys

I'm trying to make a small shooter "Binding of Isaac" kind of game and I'm attempting to use the arrow keys to shoot a projectile object. My issue is that I can shoot LEFT and RIGHT perfectly fine but no force is added for the Z axis when shooting UP and DOWN.

 if (Input.GetKey (KeyCode.RightArrow) && Time.time > nextFire) {
             //Instantiate (prefab, new Vector3 (playerBody.transform.position.x + 1f, 0.5f, playerBody.transform.position.z), playerBody.rotation);
             GameObject projectile = Instantiate (prefab, new Vector3 (playerBody.transform.position.x + 1f, 0.5f, playerBody.transform.position.z), playerBody.rotation);
             projectile.GetComponent<Rigidbody> ().AddForce (new Vector3(1000, 0));
             nextFire = Time.time + fireRate;
         }
 
         if (Input.GetKey (KeyCode.LeftArrow) && Time.time > nextFire) {
             GameObject projectile = Instantiate (prefab, new Vector3 (playerBody.transform.position.x - 1f, 0.5f, playerBody.transform.position.z), playerBody.rotation);
             projectile.GetComponent<Rigidbody> ().AddForce (new Vector3(-1000, 0));
             nextFire = Time.time + fireRate;
         }
 
         if (Input.GetKey (KeyCode.UpArrow) && Time.time > nextFire) {
             Instantiate (prefab, new Vector3 (playerBody.transform.position.x, 0.5f, playerBody.transform.position.z + 1f), playerBody.rotation);
             GameObject projectile = Instantiate (prefab, new Vector3 (playerBody.transform.position.x, 0.5f, playerBody.transform.position.z + 1f), playerBody.rotation);
             projectile.GetComponent<Rigidbody> ().AddForce (new Vector3(0, 0, 1000));
             nextFire = Time.time + fireRate;
         }
 
         if (Input.GetKey (KeyCode.DownArrow) && Time.time > nextFire) {
             GameObject projectile = Instantiate (prefab, new Vector3 (playerBody.transform.position.x, 0.5f, playerBody.transform.position.z - 1f), playerBody.rotation);
             projectile.GetComponent<Rigidbody> ().AddForce (new Vector3(0, 0, -1000));
             nextFire = Time.time + fireRate;
         }

I really don't see where the issue lies. Any ideas?

EDIT: I just realised that I froze the projectiles Z axis movement instead of Y which is what I had originally intended). The AddForce was working fine.

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

1 Reply

  • Sort: 
avatar image
0

Answer by TheGreyRaveen · Dec 27, 2016 at 05:52 PM

if I'm correct, when you shoot projectile UP and DOWN it has to fly on Y axis, not Z. For example you should have

 projectile.GetComponent<Rigidbody> ().AddForce (new Vector3(0, -1000, 0));

instead of

 projectile.GetComponent<Rigidbody> ().AddForce (new Vector3(0, 0, -1000));


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 raulismasiukas · Dec 27, 2016 at 06:07 PM 0
Share

The Y axis is up, for some reason. I had this idea as well but the projectiles just shoot up/down towards the ceiling, not up/down along the scene.

Follow this Question

Answers Answers and Comments

102 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to apply a force at certain point of an object? 0 Answers

how to change the velocity of a rigid body based on a forward 0 Answers

How can I move an object in the direction another object is facing. 1 Answer

Bullet shooting not working 0 Answers

Apply force to character based on thrusters attached to a hand like objects (multiple sources) 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