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 Lairinus · Dec 21, 2012 at 04:15 AM · c#rotationquaternion

Rotation of an Object yielding no results

Hello.

I have 3 copies of the same model. One has a default X rotation of 90, one has a default Y rotation of 90, and one has a default Z rotation of 90.

When instantiated in game, I default the rotation to the instantiated position's rotation which looks like:

 GameObject test = Instantiate(testObject, transform.position, transform.rotation) as GameObject;

As expected it spawns on the right point, and also as expected, it's facing upwards.

Then I apply a one-shot rotation to it with a simple Transform.Rotate.

 vector3 _spellDirection = viewDirection;
 
 test.transform.Rotate(viewDirection, 270);

I've tried every number possible as the second parameter, and even without a second parameter. It doesn't rotate. I've even tried it as part of a While() statement, and it fires, though doesn't move at all.

What could possibly be the issue?

My goal is to get it to face towards a certain angle, but it won't do anything but stand straight up on all instances of the models that I imported.

Thanks for any help.. Probably a pretty simple answer, though I can't get it to move at all.

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

1 Reply

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

Answer by Eric5h5 · Dec 21, 2012 at 05:04 AM

Your Rotate code does work; you have some other issue. Try trouble-shooting, and just use this:

 transform.Rotate (Vector3.up, 90);

Put that on a cube or something and it will rotate 90 degrees. However it would be more common to do:

 transform.Rotate (Vector3.up * 90);

From your description, it sounds like maybe you should use Transform.LookAt though.

Comment
Add comment · Show 5 · 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 Lairinus · Dec 21, 2012 at 05:29 AM 0
Share

I've AL$$anonymous$$OST got it working with using Transform.LookAt.

The only issue that I'm encountering is that I'm not sure what to use for the transform target parameter. Whenever I use a transform.forward of the "casting object," it seems to be a little off.

On a plus side it's now facing the general direction, just off by a few degrees because of not understanding the transform target parameter.

my code:

test.Transform.LookAt(cCamera.hero.transform.forward , spellDirection);

avatar image clunk47 · Dec 21, 2012 at 05:45 AM 0
Share

Good answer. +1.

avatar image Lairinus · Dec 21, 2012 at 06:15 AM 0
Share

I still don't know the root cause of why my rotation is off on my model (after importing 3 different variations of the same model) but for now it's working with a little discrepancy in the angles.

Eventually I'll figure it out completely but for now it'll be good, as it's only meant for a basic test of the system.

Thanks for the help.

Oh, and also, I'm using Transform.LookAt, and the cause for the slight flaw is the transform target parameter. After putting in like 200 different parameters, it still remains off.

avatar image clunk47 · Dec 21, 2012 at 06:17 AM 0
Share

Idk how you have the axes set up, or if this will help, but try parenting your model to an empty object, and attach your code to the new parent ins$$anonymous$$d of the model itself.

avatar image Lairinus · Dec 21, 2012 at 03:16 PM 0
Share

AS stated earlier, it was a noob issue. What was happening was I was exporting the model without applying the rotation and scale. The final code that's working is..

transform.LookAt(Camera.main.transform);

I applied scale on the 2 models that weren't facing the Z axis, and of course on the one that was I just exported it without thinking twice.

Thanks for the help guys; now I know about Transform.LookAt

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

11 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

Related Questions

Flip over an object (smooth transition) 3 Answers

Rotation from AngleAxis() ToAngleAxis() flips back and forth 1 Answer

How to always rotate clockwise 1 Answer

Keep objects current rotation, with Input Mouse X 0 Answers

Why is this rotation acting odd? 0 Answers


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