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 digzou · Nov 29, 2014 at 02:31 PM · javascriptlerprotatearoundslerp

Slerp / Lerp RotateAround()

I use this script to rotatearound 4 walls at angles of 90,180,270,360. Although this function works good, it stops abruptly. Is there a way to slow down the rotate around towards the end of the rotation. I tried using Time.timeScale but it slowed down the the whole game. Also I tried playing around with physics2d attributes like Drag,Angular Drag, rigidbody2d.AddForce() and rigidbody2d.AddTorque(). But cudnt acheive what I needed.

Just begun learning unity, so I dont know much about it.

Thanks in advance.

Here's my code:

  #pragma strict

  public class mgWallScript extends MonoBehaviour{

     var rotZ: int=0;
    var prefab : GameObject;
    var tprefab : GameObject;
    var thinRingPrefab : GameObject;
    var nextPrefab : GameObject;
    var localPrefab : GameObject;
    var globalWallObj : GameObject;
    var num=4;
   
    public static var radius : float =1.56f; 
    var arr = new Array ();
  
    var rotateTime = 0;
    var rotateSpeed = 10;
    var rotateDegrees =0;
    private var rotating = false;
    public var rotateing = new Array();
    var counterTime:int;
     
    static var globalObj : GameObject;
     
   function Start(){
      counterTime = 0;
      rotateing[0]=false;
      rotateing[1]=false;
      rotateing[2]=false;
      rotateing[3]= false;

     rotZ=0;
     
 for(var i=0;i<num;i++){        
         var angle=i*Mathf.PI*2/num;

         var pos=Vector3(Mathf.Round(Mathf.Cos(angle)),Mathf.Round(Mathf.Sin(angle)),0)*radius;
         
         var    obj=Instantiate(thinRingPrefab,pos,Quaternion.Euler(0,0,rotZ));
         rotZ+=90;
         
         arr.push(obj);
     }
 }
 
 function FixedUpdate(){

 rotateTime = 4;
   rotateDegrees=90;
   if(counterTime <4){
      for(var i=0;i<arr.length;i++){
      tprefab=arr[i];
      if(i==3)
      nextPrefab=arr[0];
      else
      nextPrefab=arr[i+1];
     
      RotateAllWalls(i,tprefab.transform,this.gameObject.transform, nextPrefab.transform ,-(Vector3.forward), rotateDegrees, rotateTime);
      }
      }else{
      
      counterTime = 0;
      rotateing[0]=false;
      rotateing[1]=false;
      rotateing[2]=false;
      rotateing[3]= false;
      }

    }

      function RotateAllWalls (temp:int ,thisTransform : Transform, otherTransform : Transform, nextTransform : Transform, rotateAxis : Vector3, degrees : float, totalTime : float) {
     if (rotateing[temp]) return;
     
     rotating = true;
     rotateing[temp]= true;
     
     var startRotation = thisTransform.rotation;
     var startPosition = thisTransform.position;
     
     var endRotation = nextTransform.rotation;
     var endPosition = nextTransform.position;
     
     thisTransform.rotation = startRotation;
     thisTransform.position = startPosition;
    
     var rate = degrees/totalTime;
     
     for (var i = 0.0; i < degrees; i += Time.deltaTime * rate * rotateSpeed) {
                yield;
         thisTransform.RotateAround(otherTransform.position, rotateAxis, Time.deltaTime * rate * rotateSpeed);
     }
  
     thisTransform.rotation = endRotation;
     thisTransform.position = endPosition;

     rotating = false;
     rotateing[temp]= false;
     counterTime++;
 }
 

}

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

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

2 People are following this question.

avatar image avatar image

Related Questions

Rotation with RotateAround 2 Answers

How can i smoothly rotate a gameobject 1 Answer

How to use Slerp / Lerp / RotateTowards to rotate an object (from-to) two rotations but around their Y axis only? 0 Answers

Slerp / lerp not creating a smooth transition 2 Answers

Is it possible to use a quaternion from a gameobjects position to another gameobjects position? 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