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 May 09, 2016 at 09:48 PM by Paul2357 for the following reason:

Solved

avatar image
2
Question by Paul2357 · May 06, 2016 at 06:37 PM · c#unity 5instantiateprojectileprojectiles

Problem with projectile direction

I have projectiles that the player can shoot. I have no problem instantiating them and applying the velocity for them to move. However, I cannot seem to get it to send the projectile in the opposite direction from whatever it defaults to.

For Example:

Player moving right -> shoots right Player moving left -> shoots left

I have code that should (in theory) handle it, but it doesn't seem to be listening to that code. I've checked to make sure the bool is switching and it's even hitting the break point to go into the code to make that line happen. I'm at a bit of a loss right now. I'm still working through it on my own, but would appreciate input.

 //Handles attacking
         if (Input.GetKeyDown(KeyCode.Space))
         {
             //Handle Switching Projectiles/Attacks
             switch (attackNumber)
             {
                 case 1:
                     if (movingRight)
                     {
                         Rigidbody rightShot = Instantiate(fireProjectile, transform.position + (transform.forward    * 0.5f), transform.rotation) as Rigidbody;
                         rightShot.velocity = new Vector3(bulletSpeed * Time.deltaTime, 0, 0);
                     }
                     else if (!movingRight)
                     {
                         Rigidbody leftShot = Instantiate(fireProjectile, transform.position + (transform.forward * 0.5f), transform.rotation) as Rigidbody;
                         leftShot.velocity = new Vector3(-bulletSpeed * Time.deltaTime, 0, 0);
                     }
                     break;
 
                 case 2:
                     playerMove.jumpForce = 600;
                     //playerMove.jumpForce = 600;
                     //magicUses--;
                     //Debug.Log(magicUses);
                     break;
             }
         }

I'm sure there is probably a better way to go about this, but this was the first thing I thought of to handle it. Any input would be greatly appreciated! Once I fix this, I can apply the same concept to my enemy characters to make them shoot the right direction too! :D

Comment
Add comment · Show 5
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 Baltazard · May 06, 2016 at 11:37 PM 0
Share

Hi @Paul2357

I didn't quite understand the problem. So you want the bullet to go to the right when you are moving to the right and to the left when moving left ? Also Where is the bullet going right now ?

avatar image Paul2357 Baltazard · May 07, 2016 at 03:28 AM 0
Share

@baltazard Yes I'm trying to get projectiles to fire in the direction the player is facing. Right now it travels right no matter what

avatar image Baltazard Paul2357 · May 07, 2016 at 11:36 AM 0
Share

Try maybe this : leftShot.velocity = transform.forward * bulletSpeed * Time.deltaTime

Show more comments

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

171 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 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

Instantiate is not working in unity 5.6.4f1 0 Answers

How do i Instantiate sub-Points with in Multiple Points?? 0 Answers

2.5D Projectile Help 1 Answer

how do i remember a just instantiated prefab as a variable gameobject? 1 Answer

Projectile disappears instantly after appearing. 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