How can I rotate a Transform over a specified time in a single line of code?  I have had a lot of trouble with this in the past.  I wrote a script which rotates a Transform by a specified rotation over n seconds, or rotates a Transform towards a Vector3 over n seconds, in a one liner.  I hope it helps others in the future.  See below.
121742
I'm trying to make a plane rotate down a certain amount and 180 degrees horizontally over 2 seconds.  Basically I want it to take the plane 1 second to rotate to a horizontal-facing angle, then take the other second to rotate 180 degrees around to face the other direction.  The formula I'm currently using is:      //If you're rotating, lower the speed and rotate the plane.     if (rotate == 1 &amp;&amp; rotationPhase &gt; 0) {         //If in phase 0, figure out which phase you need too go to.         if (angle &gt; 90 &amp;&amp; rotationPhase == 1) {             //Rotation phase 2 = rotating down             rotationPhase = 2;             rotationAngleTime = angle - 90;         }         else if (rotationPhase == 1) {             //Rotation phase 3 = rotating up             rotationPhase = 3;             rotationAngleTime = 90 - angle;         }          //After phase 0, if in phase 1 begin rotating down, if in phase 2 begin rotating up.         if (angle &gt; 90 &amp;&amp; rotationPhase == 2) {             transform.Rotate(0, 0, -rotationAngleTime * (Time.deltaTime * (rotationSpeed / 2)));             angle -= rotationAngleTime * (Time.deltaTime * (rotationSpeed / 2));             if (angle &gt; 89 &amp;&amp; angle &lt; 91) {                 angle = 90;                 rotationPhase = 4;                 rotationAngleTime = 180;             }         }         else if (rotationPhase == 3) {             transform.Rotate(0, 0, rotationAngleTime * (Time.deltaTime * (rotationSpeed / 2)));             angle += rotationAngleTime * (Time.deltaTime * (rotationSpeed / 2));             if (angle &gt; 89 &amp;&amp; angle &lt; 91) {                 angle = 90;                 rotationPhase = 4;                 rotationAngleTime = 180;             }         }          //After you have rotated to horizontal in phase 1/2, rotate around to face the other direction.         if (rotationPhase == 4) {             transform.Rotate(rotationAngleTime * (Time.deltaTime * (rotationSpeed / 2)), 0, 0);             rotationAngle += rotationAngleTime * (Time.deltaTime * (rotationSpeed / 2));             if (rotationAngle &gt; 179) {                 rotationAngle = 0;                 rotationPhase = 0;                 rotationAngleTime = 0;             }         }     }   I've tried many different things, but I can't figure out what to do.  EDIT: This seems to be a problem with Time.deltaTime. I can get the plane to rotate correctly, but for some reason it's not rotating over the right amount of time. I have a timer being subtracted by Time.deltaTime, and this animation happening, and the animation always finishes about half a second before the timer runs out.
11563
I am attempting a simple script to swing a door open in Unity.  This requires a smooth rotation of 90 degrees around the Y axis.  I have seen that one way to do this is using Unity's Quanternion object.  I believed that this should work:  public class DoorOpenScript : MonoBehaviour  {      public float smooth = 20;      // Use this for initialization     void Start ()      {            SwingOpen ();     }      // Update is called once per frame     void Update ()      {      }      void SwingOpen()     {            Quaternion newRotation = new Quaternion(transform.rotation.x,transform.rotation.y,transform.rotation.z,transform.rotation.w);;         newRotation *= Quaternion.Euler(0, 90, 0); // this add a 90 degrees Y rotation         transform.rotation= Quaternion.Slerp(transform.rotation, newRotation,20 * Time.deltaTime);            }  }   However, this just opens the door completely. I have tried playing with the third parameter to Slerp but with no results. What am I doing incorrectly?
31775
I've problem Rendering sun rotation animation. Steps to reproduce:   Create the sun object Set 1st keyframe   Select keyframe Rotate sun object using the handle "I" > Select Rotation  Set 10th keyframe (Reproduce same steps found in 2nd point)  Add frame_change_post handler to print sun rotation_euler Run Render > Render Animation   The result was 11 times (0-10) printed same rotation Euler &lt;Euler (x=-7.9113, y=0.2392, z=-7.1615), order='XYZ'&gt;  .But when I move from keyframe to keyframe Euler XYZ positions are updated. Why is that so?  Here is a demo plugin created to replicate the issue:  bl_info = { "name": "Sun animation using lever", "author": "karlisup", "version": (1, 0), "blender": (2, 80, 0), } import bpy from bpy.app.handlers import persistent  @persistent def sun_handler(scene, depsgraph):     if "Sun" not in bpy.data.objects:         create_sun()     sun = bpy.data.objects["Sun"]     print(scene.frame_current, sun.rotation_euler)  def create_sun():     bpy.context.view_layer.active_layer_collection = bpy.context.view_layer.layer_collection     light_data = bpy.data.lights.new(name="Sun", type='SUN')     light_data.energy = 30     light_object = bpy.data.objects.new(name="Sun", object_data=light_data)     light_object.location = (5, 5, 5)     bpy.context.collection.objects.link(light_object)     bpy.context.view_layer.objects.active = light_object  def register():     bpy.app.handlers.frame_change_post.append(sun_handler)  def unregister():     bpy.app.handlers.frame_change_post.remove(sun_handler)  if __name__ == "__main__":     register()
111117
I am currently 3d modeling a twisty puzzle and trying to animate it. I have the puzzle done but when I try to animate it, it randomly twists and turns the individual objects in different directions before converging back to their original form at the end of the animation.  The screencast of me attempting to animate this is here:   File at the end of the screencast:    This is the original file. Just delete the 2 keyframes that are there:    I did make this with a tutorial. It is by rcpongo and I have very slightly edited his design. All credit goes to him for my design.
6938
Is there one central reason why there is no "Time" operator in QM?  I know this question has been asked before, but I thought I would try to stimulate some fresh thinking.
46298
I have developed several puzzles in Blender, and to test them I wanted to animate them.   The first problem I encountered was the rotation of an object around a central hub.   Between keyframes the object would cut across rather than follow the circular path.   To solve this I moved the origins to the centre of rotation, and that worked fine.   The next problem was to move the rotation of one or more of the objects to another hub.   This is where it gets a bit tricky!   It's not practical to have to keep changing individual origins for every keyframe.   I've tried parenting to the hubs but this doesn't make it any easier.   Perhaps there is a way with armatures?   Maybe I've missed something very basic.  I made a small demo to illustrate the kind of rotation I mean:   Keyframe 1.   Keyframe 2.   Keyframe 3.  At this stage there are three answers to my question, and all of them require constraint influences to be turned on or off for each object that needs to change its centre of rotation. Multiply this several times and it becomes a bit of a nightmare!  I'm thinking that to position the 3d cursor at the centre of the wheel and then select all the objects required to turn for each rotation might be easier than the answers so far, but I was hoping for something more straight forward than that.  Don't get me wrong, I do appreciate the effort you guys have put in so far, thanks. :)
111531
I have written up a script for my model. But there is a bit of a problem with it. As in I have to run the script every time I open the file. I want the script to run automatically when I open the blender File.
44360
Just trying to do my first animation and am struggling to make it loop seamlessly. I think the differing rotational speeds of the 2 objects are the thing to overcome but I'm not sure how.  I basically want the earth to do one revolution to the teapot's 2 orbits around the earth.  Can anyone have a look at this  and advise me?  Thanks in advance.
67922
I am trying to rotate an object using python, inline with a vector which gives me the direction I want (based on the difference between the last two coordinates of the curve I generated). I therefore have a vector which I'd like to align this object but not the XYZ angles. The options to specify rotation (XYZ Euler...) all seem to require some sort of angle definition. I've started playing with numpy with I'm not experienced enough to find the answer. Would you be able to advise what would be the best way to align an object to a vector and (if necessary) how I could convert the vector coordinates in XYZ_Euler angles I could apply to the object? for instance, Vector=[1,1,1] and I would like to rotate the object along this vector. Thanks for your help  update Thanks guys, DirectionVector.to_track_quat('X', 'Z') did the trick very nicely! #define direction Vector=(1,1,1) DirectionVector = mathutils.Vector(Vector)  #apply rotation bpy.context.object.rotation_mode = 'QUATERNION' bpy.context.object.rotation_quaternion = DirectionVector.to_track_quat('Z','Y')
87246
I'm using this code in my script to move a gameobject:  void Update () {      // Move the object forward along its z axis 1 unit/second.     transform.position = new Vector2(transform.position.x , transform.position.y - 0.2f);  }   On screen the movement is a bit jaggy and not fluent.  Is there a different approach?  Hint: Please do not suggestion to use rigidbody functions since adding rigidbody would disrupt everything I did.  Can I use FxedUpdate?  Mirza
116666
How can I keep the rotation values within a range of 0 to 360° no matter how many times I actually rotated an object? I need this as a value for a driver variable.  For example 945° => 225°.
3000
I want to rotate all the images in a directory that match a pattern.  So far I have:  for file in `ls /tmp/p/DSC*.JPG`; do   convert $file -rotate 90 file+'_rotated'.JPG done   but that gives no output?
102556
I have a basic menu script with a slider. The idea is that the slider will control the rotation of a bone. That bone will then rotate the object. I worked out the exact euler angles to rotate it by, and now I'm a little bit stuck. I've used C# for quite some time and C# has this thing called , and I wondered if there is a python equivalent? If so, what is it?  Here is what I'm aiming for:  elif origin == 'screen_rotation':     bones = bpy.context.object.pose.bones      Mathf.Lerp(bones["Screen"].rotation_euler[1] = 0, bones["Screen"].rotation_euler[1] = 1.58825, screen_rotation)
21443
Is there any standard that covers the portability of running a command after variable assignment on the same line?  APPLE="cider" echo hi   How portable is something like that? Where will it work and where won't it?   Also: my shell scripts start with #!/bin/sh if that makes any difference.
82458
In order to optimize my script, I would need some help to perform a rotation around the cursor (see )  With low-level python, that means, without bpy.ops.* operations.  I have to admit that I didn't find a good overview on how to make rotation with python without bpy.ops. Do I have to perform matrix operations for a simple rotation around an axis Z located at the cursor position?
63452
I am the lucky owner of a pivot monitor, which screen can be rotated (physically). What is the easiest way to make my display turn when I turn my monitor?  For the moment I first launch the 'Displays' app, and then change the settings and confirm. But this is in fact quite a laboured procedure, since I want to switch my orientation up to a few times per minute.  So is there an indicator for this, or equivalent? Can I set a keyboard shortcut that would launch a dedicated command? In fact I am thinking of something similar to the Windows program .
16837
I've written a quick-and-dirty script to time some reports from a web service:  BASE_URL='http://example.com/json/webservice/' FIRST=1 FINAL=10000  for report_code in $(seq 1 $FINAL); do   (time -p response=$(curl --write-out %{http_code} --silent -O ${BASE_URL}/${report_code}) ) 2&gt; ${report_code}.time    echo $response  # &lt;------- this is out of scope!  How do I fix that?   if [[ $response = '404' ]]; then     echo "Deleting report # ${report_code}!"     rm ${report_code}   else     echo "${report_code} seems to be good!"   fi done   I need to wrap the time command in a subshell so I can redirect its output, but that makes the value of $response unavailable to the parent shell.  How do I get around this problem?