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 /
avatar image
0
Question by unity_9EerIPIEh8yPGg · May 11, 2020 at 01:04 PM · instantiatetransformscripting beginnerbulletc++

Bullet firing but prefab looking in the wrong direction

Hi, beginner here, I wanted to recreate a little tank game i played during childhood, but I have a problem with my bullets. When fired, they follow the good trajectory ( bullet's forward direction = blue arrow) but the prefab is facing 90° right. I've model the bullet in blender, modify it's orientation in blender then put it back in unity but it doesn't change anything. I've tried several things, the bullet spawn with the position/rotation of the turret and it follow this script : alt text

alt text

capture.png (18.0 kB)
sans-titre.png (179.2 kB)
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 ShadyProductions · May 11, 2020 at 01:18 PM 0
Share

Can't you just copy the rotation of the tank's barrel as it's the same rotation the bullet should be facing?

avatar image KapoorArjun19 · May 11, 2020 at 01:22 PM 0
Share

The bullet should spawn at the position of the turret and have its own rotation (bullet's rotation) as spawning rotation ins$$anonymous$$d of being a turret rotation.

avatar image unity_9EerIPIEh8yPGg KapoorArjun19 · May 11, 2020 at 04:12 PM 0
Share

hi, thx for relpying. I'm making the bullet spawn on an empty object sitting on the gun and i'm using Instantiate(bulletPrefab, transform.position, transform.rotation); to make it spawn. Is that not the good way ?

avatar image KapoorArjun19 unity_9EerIPIEh8yPGg · May 12, 2020 at 04:58 AM 0
Share

Thats okay but you need to set the transform.rotation as the desired rotation you want the bullet to have.

avatar image Hellium · May 12, 2020 at 07:03 AM 0
Share

If the bullet goes in the correct direction with the transform.forward, it means your model is incorrectly oriented.


If you drag & drop the bullet prefab in an empty scene, is the blue arrow (+Z axis) in the same direction as the bullet? If not you have to fix this in your modelling software.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by millej23 · May 12, 2020 at 01:15 PM

Is your bullet a Prefab? I would make it one, make sure the directions are what you want, then instantiate it using something like the example:

https://docs.unity3d.com/ScriptReference/Object.Instantiate.html

 public class ExampleClass : MonoBehaviour
 {
     // Instantiate a Prefab with an attached Missile script
     public Missile projectile;
 
     void Update()
     {
         // Ctrl was pressed, launch a projectile
         if (Input.GetButtonDown("Fire1"))
         {
             // Instantiate the projectile at the position and rotation of this transform
             Missile clone = Instantiate(projectile, transform.position, transform.rotation);
 
             // Set the missiles timeout destructor to 5
             clone.timeoutDestructor = 5;
         }
     }
 }
Comment
Add comment · Show 2 · 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 unity_9EerIPIEh8yPGg · May 15, 2020 at 11:36 AM 0
Share

Hi, Yes my bullet iss a prefab and it's Instanciate like so : alt text

capture.png (12.1 kB)
avatar image millej23 unity_9EerIPIEh8yPGg · May 15, 2020 at 11:51 AM 1
Share

You may need to re-do your prefab and check the rotation of that. Or what I usually do is make an empty gameobject, like "gunBarrel" where the bullet shoots from. This way you can change the empty object rotation the way you like without affecting your player, and its easier to make changes to the bullet tranforms with code, etc, for me anyway. Hope that helps!

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

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

Bullets Based on Orientation 1 Answer

How to grab, store and reference an objects position on trigger? 1 Answer

Top-down shooter shooting problem 1 Answer

Going crazy over simple bullets not instantiating in the correct position 0 Answers

Rotation and Velocity of bullets. 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