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 Tona999 · Nov 18, 2015 at 04:29 PM · rotationinstantiateprefabspeedscrip

GameObjects rotation

Hey folks, I am making a 2D game in which there are obstacles (like birds) moving on the X-Axis from the left to the right or viceversa and are prefabs. They have a moving speed . I've put a collider which instantiates a random Obstacle in his position when OnTriggerEnter2D() is true. Now, this instantiator has an Array of Obstacles and all of them are facing to the right, so their moving speed is positive. If I want to instantiate a random obstacle facing to the left I (obviously) use the instantiate function giving it as a parameter the angle of the obstacle facing the right + 180 degrees. So far so good but if I try to change the speed to a negative value , so the object will move to the left and not to the right, it seems to be changing the speed of the original obstacle in the array which was facing to the right. So the next time I try to instantiate a new obstacle facing the right its speed is negative ... and this is a problem. Any ideas on how to acomplish this ? And nope,I don't have the script . I got angry and deleted it sorry .

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 vintar · Nov 18, 2015 at 06:45 PM 0
Share

I think you should rather change the transform.localScale to (-1, -1 , -1) ins$$anonymous$$d of rotating it 180 degrees

avatar image Soos621 · Nov 18, 2015 at 08:40 PM 0
Share

first of all, you shouldn't ever delete your scripts if you are still working on them. This not only makes it harder for people to help you, but you may want to go back and revise things or even copy and paste some parts, secondly, you can always set the speed on an object in a direction based on its transform so you can do something like:

this.transform.position = this.transform.position + this.transform.forward * speed;

that will always move the object in the direction it is facing regardless of its rotation. (use vector3.lerp or vector2.lerp to smooth out the movement)

0 Replies

· Add your reply
  • Sort: 

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

Instantiated Object Has Wrong Rotation 0 Answers

How to make another ground spawn beneath itself 1 Answer

How do I set a transform to a prefab? 1 Answer

Im having an issue when Instantiate Prefab with specific rotation 2 Answers

instantiated prefab doesn't follow spawn rotation 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