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 /
avatar image
1
Question by Hellwalker · Apr 21, 2010 at 08:11 AM · rotationangles

Setting rotation Angle / rotation question

Hello,

can I set objects rotation angle (vs rotating it by some degree?) say set angle 90, (on local axis)

long version

I have Cylinder with 6 sides, some object is moving on a path through this cylinder. this object is at the center of the cylinder all times, another object is attached to it and is some distance away from this object. alt text

sorry for the crappy pic (: did it in paint

I want to rotate it left 60 degrees when A is hit, and rotate right 60 degrees when I hit D. basically its like sides of cylinder are racing tracks, and with each rotation player is moved(rotated) to the center of next side.

I'm using this script

var rotation = 0;

function Update () { //rotate player when Ais hit if (Input.GetKeyDown ("a")) { // rotation += 0.2; transform.Rotate (rotation,0,0); } if (Input.GetKeyDown ("d")) { // rotation += 0.2 transform.Rotate (rotation*-1,0,0); } }

and I get some weird result like 29.9, 30.1 rotations when default rotation of null is 90 O_O so I figured if I have array with each possible angle in it, and I directly set angle of object to some degrees I will avoid this weird angles. but how do I do that?

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 Hellwalker · Apr 21, 2010 at 08:13 AM 0
Share

code tag didnt work ;/

avatar image duck ♦♦ · Apr 21, 2010 at 09:19 AM 0
Share

there's a code button when you're editing (it has 010101 on it), which just indents the text by 4 spaces. That's all that is needed to format code.

1 Reply

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

Answer by duck · Apr 21, 2010 at 09:16 AM

How are you moving your null object along the centre line of the tube?

Are you also aligning your object with the direction of the tube's path?

What you should be doing, each Update() is this:

1) Set your null object to the new position along the path

2) Set your null object's rotation so that it is aligned with the path direction. For example:

nullObject.transform.rotation = Quaternion.LookRotation( pathDirection );

3) Now rotate the null object around its own local forward axis by the full amount (because the previous command will have reset the rotation entirely):

nullObject.Rotate(Vector3.forward * playerAngle);

So, when put together, your Update() function might look something like this:

float playerAngle = 0; float turnSpeed = 30;

void Update() {

 playerAngle += Input.GetAxis("Horizontal") * turnSpeed * Time.deltaTime;

 transform.position = GetPathPosition();
 Vector3 pathDirection = GetPathDirection();
 nullObject.transform.rotation = Quaternion.LookRotation( pathDirection );
 nullObject.transform.Rotate(Vector3.forward * playerAngle);


}

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 Hellwalker · Apr 21, 2010 at 10:47 AM 0
Share

thx for the reply. I'm using Spline Controller for path http://www.unifycommunity.com/wiki/index.php?title=Spline_Controller and it does not set objects rotation, just position(if i'm not mistaken) http://j.imagehost.org/0316/untitled_2.png (direction is same as on horizontal, even though path curves)

I don't really know how paths work, but i will try to figure it out

avatar image duck ♦♦ · Apr 21, 2010 at 11:39 AM 1
Share

To get the current direction of the route, just get the position of another point slightly further along the spline, and do: (furtherPosition-currentPosition). This gives you a vector whose direction is the direction of the spline at that point.

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

Rotate on one axis and check if angle is inside desired range 2 Answers

Set rotation based on 1,1,1 style vector? How to convert vector3 to quaternion? 1 Answer

How to Find an Object close to where the Player is Looking 1 Answer

Calculating the corners of a GameObject (sprite) with Quaternion.Angle 2 Answers

Problem with angles and rotations in a 2D top down space shooter 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