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
1
Question by jmccnz · Jun 17, 2012 at 03:13 PM · transformrotate

Transform.Rotate irrespective of local rotation?

Hello,

I am having slight difficulty implementing a simple linear projectile like motion for a moving transform. During the time the transform is in the air I want to slowly adjust its rotation so it will gradually face the ground during the motion rather than flying up and falling backwards. Here is what I have so far:

    if (!rwc.isGrounded) {
     currentAir += Time.deltaTime;
     transform.Rotate (0.5f, 0, 0); //0.5 deg a frame
    }

This works well for a jump where the transform rotation doesn't change however if I jump at an angle the transform will rotate respective of its local "down" rotation and not the global down rotation I would like - this gives a curved jump motion.

Is there any way I can adjust the x rotation in this way?

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 Owen-Reynolds · Jun 17, 2012 at 04:03 PM 0
Share

It sounds like you're manually moving the object forwards, something like transform.Translate(0,0,1);. That won't give "real" jumping motion. It will be more like a swim$$anonymous$$g.

$$anonymous$$ost jumping either uses the gravity code from the charController scripts, or a rigidbody, which runs all the math for you.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by aldonaletto · Jun 17, 2012 at 03:23 PM

You will never match the rotation to the movement using this method. It's better to adjust the object orientation to direction it's moving, like this:

Vector3 lastPos;

void Start(){ lastPos = transform.position; }

void Update(){ Vector3 dir = transform.position - lastPos; if (dir.magnitude > 0.2f){ // update direction/lastPos only after at least 0.2 distance transform.forward = dir.normalized; // point the movement direction lastPos = transform.position; // update lastPos } } This will make the object set its forward direction always to where it's moving. If you want to align other directions, change the transform vector (use transform.up, for instance).
NOTE: If you want to control the object rotation anyway, define the world space in Rotate, like this:

  transform.Rotate (90 * Time.deltaTime, 0, 0, Space.World); // 90 degrees per second

and multiply the angle by Time.deltaTime, so the rotation speed will be constant and expressed in degrees per second, no matter which's the framerate.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Rotate z and y together? 1 Answer

How to rotate without a target vector 1 Answer

Orientation Vs. Rotation: How do I specify more than 360deg rotation for a quaternion, in the editor? 1 Answer

Rotation Help 2 Answers

Calc 30° left and x units forward from local forward axis 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