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 /
avatar image
1
Question by Misthra-Games · Jan 14, 2016 at 04:00 AM · c#rotationspawn

Object spawn rotation

Hi so i have a spawn script for a bullet. And. When it spawns, it doesnt spawn with the same rotation as the object the it spawns from.

Could some tell me what to do?

Heres my code

using UnityEngine; using System.Collections;

public class SpawnProjectile : MonoBehaviour {

 public GameObject projectile;



 public float ROF = 0.0f;

 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {


     if (Input.GetMouseButtonDown (0) & ROF >= 10.0f) {
         
         Instantiate (projectile, transform.position, Quaternion.identity);
         ROF = 0.0f;
     }
 
     if (ROF < 10.0f) {
         ROF += 0.1f;
     }
 }

}

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by rob5300 · Jan 14, 2016 at 10:26 AM

That is because Quaternion.identity is a pre-made Quaternion witn no rotation (0,0,0). I would assume you can see when you execute that the projectile has this rotation.

You already did the right thing by using transform.position when Instantiating projectile.

You want to pass transform.rotation from the parent object you mention. Assuming this MonoBehaviour is attached to it you can get that my referencing ether transform.rotation, this.transform.rotation or GetComponent<Transform>().rotation.

Excuse me if there are errors in this, i haven't used Unity for a little while.

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 Misthra-Games · Jan 14, 2016 at 08:42 PM 0
Share

how would this look in my code?

avatar image rob5300 · Jan 14, 2016 at 10:51 PM 0
Share

You would replace Instantiate (projectile, transform.position, Quaternion.identity); with:

Instantiate (projectile, transform.position, transform.rotation);

Note that we have altered the 3rd argument from referencing Quaternion.identity, a blank rotation value of 0,0,0 to using transform.rotation, which is the rotation data from the Gameobject this script is attached to.

avatar image
0

Answer by DarKMaskMaster · Apr 18, 2020 at 12:31 PM

Hello rob5300

I am trying to get that running on a timer for an enemy but it doesnt sem to work. can you help me out? This is the script:

public GameObject projectile; public float ROF = 0.0f; // Use this for initialization void Start() {

 }
 

     public float targetTime = 0.1f;

     void Update()
     {

         targetTime -= Time.deltaTime;

         if (targetTime <= 0.0f)
         {
             timerEnded();
         }

     }

     void timerEnded()
     {
         Instantiate(projectile, transform.position, transform.rotation);
         ROF = 0.0f;


         if (ROF < 10.0f)
         {
             ROF += 0.1f;
             //do your stuff here.
         }
         // Update is called once per frame
     }
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

61 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

Related Questions

Rotated object raycasting in wrong directions!!? 3 Answers

How to convert User Values into degree(Angle)?? 2 Answers

Instantiated Object Has Wrong Rotation 0 Answers

Freeze rotation X but rotation Z, how can I do this? 0 Answers

Struggling to get the rotation the player is moving in. 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