Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Rydrako · Dec 13, 2010 at 12:53 AM · rotationinstantiate

How to rotate an Instantiated object?

Hello i need help rotating lasers becuase when my player rotates, the laser does not face the direction the player is shooting. Here's some of my script right now -

var ourRotation : int = transform.rotation.y;

if(Input.GetButtonDown("Jump")) {

//create our laser

var laser0 = Instantiate(laserPrefab, transform.Find("spawn").transform.position,Quaternion.identity);

//add force to our laser

laser0.rigidbody.AddForce( transform.forward * force);

//rotate our laser

laser0.Rotate(0, ourRotation, 0);

}

Comment
Add comment · Show 1
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 Justin Warner · Dec 13, 2010 at 02:51 AM 0
Share

Can you put code tags around it? And sorry, I can't help to much... Check the API, they have some stuff on it there...

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Helix · Dec 13, 2010 at 03:14 AM

Hullo Game hound,

It's hard to tell exactly how your laser prefabs work, but looking at your code, there are a couple of things you could try changing. For starters, I'd make var ourRotation a float instead of an int, for the sake of precision. I don't see why you'd even need to use an extra variable for rotation in this case, the line

    var laser0 = Instantiate(
laserPrefab, transform.Find("spawn").transform.position,Quaternion.identity);

could be re-written as

    var laser0 = Instantiate(
laserPrefab, transform.Find("spawn").transform.position,transform.rotation);

Possibly, the reason your code didn't work, was that laser0.Rotate should be laser0.transform.Rotate. I don't think that should even compile without error. Again, I don't know how your lasers work exactly, but you can prolly leave that bit out now, making the final result...

if(Input.GetButtonDown("Jump")) {

var laser0 : GameObject = Instantiate(laserPrefab, transform.Find("spawn").transform.position,transform.rotation);

laser0.rigidbody.AddForce( transform.forward * force);

}

Hope this helps!

Comment
Add comment · Show 3 · 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 Rydrako · Dec 14, 2010 at 12:19 AM 0
Share

Well it didn't work, but I should tell you how the lasers work - They're just only a simple cube with a scale of (0.5, 0.5, 1), it's kind-of my first game, and it's a prefab as you can tell from the var's name. Also look at this scenario - A player shoots when he's at 0 degrees ,y, and it looks good, but when he's not at 0 or 180 degrees ,y, the laser still is still spawning a (0,0,0) rotation.

avatar image Helix · Dec 14, 2010 at 02:28 AM 0
Share

So its moving in the right direction but not facing the right way? Wierd. Is the laser prefab running a script that could be resetting the rotation? You could add in laser0.transform.Rotate() and try putting in any values at all to test if this affects the laser's rotation, or if there is something else to blame.

avatar image Rydrako · Dec 14, 2010 at 10:56 PM 0
Share

I went to my laser's script (wich is a "OnCollisionEnter" script) and added

function Start () { transform.Rotate(0, gameObjeect.Find("SpaceShip").transform.rotation.y,0); }

. . .I also got rid of the rotate code in the script that I showed and still didn't work maybe there is something else blame, but I'll try different rotation codes.

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

No one has followed this question yet.

Related Questions

How to rotate an instantiated object by a fixed amount before it is spawned 2 Answers

Upon being instantiated, why is my object moving upwards ? 2 Answers

Android based ARCore example ObjectManipulation using Joystick Controller 0 Answers

Instantiated object rotation abruptly. 0 Answers

Instantiate question 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