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 Mr.Snippy · Aug 12, 2013 at 03:22 PM · c#rotationrigidbody

Rotate rigidbody over time

Hello Everyone,

I am trying to rotate a rigidbody smoothly over time, the setting is: there is a bridge connecting A and B (pivot point at A), I need to rotate it so that it connects A and C.

A ------- B
|
|
C

Please note that my character needs to stand on the bridge during rotation, therefore I can't use any of the following:

1) transform.rotation = Quaternion.Slerp (...) ,since the character would fall
2) rigidbody.rotation = Quaternion.Slerp (...) ,same as above
3) rigidbody.MoveRotation(...) since it doesn't show the movement process

I also did try AddTorque but it seems to rotate around objects center, not pivot point.

Any pointers would be appreciated :)

Comment
Add comment · Show 3
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 ShadoX · Aug 12, 2013 at 03:40 PM 0
Share

perhaps you can change the pivot point or just come up with a solution that would prevent the player from falling off the bridge during rotation?

avatar image Mr.Snippy · Aug 12, 2013 at 04:25 PM 0
Share

thanks, but changing the pivot point wouldn't help cause I need one bridge rotating back and force to connect these 3 points (A, B,C).

and I need character not to fall as well as move along with the bridge.

avatar image clunk47 · Aug 12, 2013 at 06:58 PM 1
Share

Try using localEulerAngles. In this example, I set a max angle on the Y axis to 90, and a speed of 15 * Time.deltaTime.

 //C-Sharp Example
 
 using UnityEngine;
 using System.Collections;
 
 public class Example : $$anonymous$$onoBehaviour
 {
     public float max = 90f;
     public float speed = 15f;
     Vector3 cur;
         
     void Start()
     {
         cur = transform.localEulerAngles;
         max = transform.localEulerAngles.y + max;
     }
     
     void Update()
     {
         transform.localEulerAngles = cur;
         
         if(cur.y < max)
         {
             cur.y += speed * Time.deltaTime;    
         }
     }
 }




 //Javascript Example
 
 
 var max : float = 90f;
 var speed : float = 15f;
 private var cur : Vector3;
     
 function Start()
 {
     cur = transform.localEulerAngles;
     max = transform.localEulerAngles.y + max;
 }
 
 function Update()
 {
     transform.localEulerAngles = cur;
     
     if(cur.y < max)
     {
         cur.y += speed * Time.deltaTime;    
     }
 }
 

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by chronicfail · Aug 12, 2013 at 04:20 PM

You can change the pivot point- use

 var center : Vector3;
 
 function Start () {
 rigidbody.centerOfMass=center;
 }

but I think the standard solution to this is to make an animation for the bridge movement.

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
avatar image
0

Answer by Owen-Reynolds · Aug 13, 2013 at 12:12 AM

If you want to do it using physics, "anchor" the end of the bridge. A cheap way is to set centerOfMass as chroncil mentions (a CoM of 000 is the real object pivot point. It uses local coords, so set X to negative 1/2 length of bridge.) The bridge will act like it has a lead weight at that end, and the rest is paper. Could also use a hinge (can attach/remove these on the fly if you need to.)

Then can push it with rigidbody.MoveTowards (just don't move it all at once - a little each frame like in the docs example.) Or can set AngularVelocity directly (in radians -- 6.28 is one full spin/second.)

The problem, is, the player will tend to slide off, even if you increase friction. This is probably a "gamey" problem. A real bridge rotating at a speed that looks good in a game really would fling human beings against and over the rails, and off the end.

The most common solution is to cheat by temporarily childing the player to the moving bridge. Then you can just use transform.rotate (if the pivot is moved to one end through parent tricks) or whatever is easier.

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

19 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

Related Questions

Flip over an object (smooth transition) 3 Answers

How to rotate an object to a specific angle with angularVelocity? 0 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Bullet not moving towards player 3 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