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
0
Question by martibergoglio · Nov 22, 2015 at 11:46 AM · rotationinstantiateprefabinstantiate prefab

Im having an issue when Instantiate Prefab with specific rotation

So, here is the thing, Im traying to instantiate a bullet prefab on my Enemy Ship, i put a child GameObject into my Enemy Ship called SpawnPoint and by reference on the inspector i use it transform.position and transform.rotation to instantiate my Bullet.

The Enemy ship and the Enemy Bolt have a "Mover" script with 2 line of code:

 public class Mover : MonoBehaviour {
  
         public float speed;
  
         Rigidbody myRigidbody;
  
  
  
         void Start () {
                 this.myRigidbody = GetComponent<Rigidbody>();
                 this.myRigidbody.velocity = Vector3.forward * this.speed;
         }
  
 }

The Enemy Ship have a WaeponController()

 public class WeaponController : MonoBehaviour {
 
     public GameObject shot;
     public Transform shotSpawn;
     public float delay;
     public float fireRate;
 
     AudioSource audioSource;
 
 
 
     void Start () {
         this.audioSource = this.GetComponent<AudioSource>();
         InvokeRepeating("Fire", this.delay, this.fireRate);
     }
 
     void Fire () {
 
         Instantiate(this.shot, this.shotSpawn.position, this.shotSpawn.rotation);
         this.audioSource.Play();
     }
 
 }

Like you can see, the Instantiate() function use the shotSpawn reference for position and rotation, the problem is that the Bolt enemy prefab instantiated never take that rotation, always go at the opposite side of the screen..

Is there a logical explanation?

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 fredz0004 · Nov 23, 2015 at 08:36 AM 0
Share

I am going to take a guess, rotation needs to be a Quaternion.

http://docs.unity3d.com/ScriptReference/Transform-rotation.html

avatar image martibergoglio fredz0004 · Nov 23, 2015 at 03:08 PM 0
Share

this.shotSpawn.rotation is not a Quaternion? $$anonymous$$aybe i have to reference it in a Quaternion first? Like Quaternion quat = this.shotSpawn.rotation

Edit: nope, it does not work...

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by kevinrocks_786 · Nov 24, 2015 at 12:13 AM

Try removing the "this." from this.shotSpawn.position, this.shotSpawn.rotation

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 martibergoglio · Nov 24, 2015 at 11:20 AM

I tryed but not working. I think something wierd is happening with my shotSpawn rotation, while turning the object, the arrows that represent it never change position...

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

40 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

Related Questions

I need help destroying a clone on function. 1 Answer

All instantiated objects having same location, 0 Answers

Prefabs not instantiating after build 0 Answers

GameObjects rotation 0 Answers

How to spawn a prefab at a duplicate objects location 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