## How do you rotate a sprite in pygame?

I am making a game in pygame and I want it so every time the sprite jumps it rotates mid-air and lands on its side. A lot like geometry dash jumping if you have ever played that. How would I do this?

## How can I rotate the player only to -40 or -45 degrees?

``float c = 0.0f; private void FixedUpdate() {     if (startRotatingBack)     {         var p = transform.eulerAngles;          if (p.y != -40)         {             p.y -= 1;             transform.eulerAngles = p;         }          c = c + 0.1f;         playerAnimator.SetFloat("Forward", c);     } } ``

The problem is that the transform keeps rotating nonstop.

Maybe the problem is with this chick?

``if (p.y != -40) ``

I want to make that the player will rotate backward. -40 or -45 is good enough but the player the transform is eep rotating nonstop so it’s making circles instead of rotating once to -40 or to -45.

## How can I rotate the two endpoints of a line around the line’s center in 3d?

The object is a capsule. I have the position of the object vector3, and the orientation of the object, a quaternion. I want to construct a line which goes through the middle of the capsule with the two endpoints of the line being the top and bottom.

The capsule can be rotated in all 3 dimensions.

## Rotate a Polygon node in Shader Graph

I have a hexagon in the Polygon node I would like to rotate so the pointy side is upwards. Applying the rotation nodes, however, simply changes the color of the hexagon from white to a color in the rainbow.

What does the `Vector1` of the Polygon output represent and is there a way I can rotate it as if it were a texture?

## im trying to rotate the player in a certain way that makes it look like he is sliding

I’m trying to make my first game in unity a 3d platformer inspired by the classic crash bandicoot games, I’ve managed to make most of the movement however I don’t know how I can do a slide/crouch since what I want to do is basically a way to rotate and move the player down closer to the ground and give him some more speed that decreases over time until he reaches a normal waking state, I thought about making the player rotate on a specific axis but when he turns the axis don’t change so now I’m kind of lost in what to do.

## How do I rotate a bone using Gizmo-style via code?

I wanted to find out how I could move a character’s arms up and down in a straight way. After some trial and error I believe that it’s not sufficient to use just X, Y or Z rotation, but that all 3 have to be used instead.

At least I think so because at some point I found out that using the Rotation Gizmo tool would do exactely what I need.

I could simply play with the one axis (marked with red arrows in my screenshot), and it would move my arms up or down.

When I watched the rotation values in the Inspector, I saw that X, Y and Z rotation changes as I use this one Gizmo axis.

I am now wondering how I could implement this in code.

Is there a formula that would turn the degree value of the Gizmo tool into a Quaternion that I could use on the bone’s rotation?

Thank you!

Edit:

I have tried the following formula to simulate rotating via the Rotation Tool, but it doesn’t behave like the Rotation tool. I gues that is because the Rotation Tool provides new Rotation values for X, Y and Z, and in my attempt, I only provide new Y rotation.

``using System.Collections; using System.Collections.Generic; using UnityEngine;  public class MyPlayer : MonoBehaviour {     public Transform Shoulder;      private Quaternion _Rotation;     private float _f = 0f;      void Start()     {         _Rotation = Shoulder.rotation;     }      void Update()     {      }     private void OnGUI()     {         if (GUI.Button(new Rect(0, 70, 50, 30), "+"))         {             _f += 1;             Vector3 newRotation = _Rotation * new Vector3(0, _f, 0);              Shoulder.Rotate(newRotation, Space.World); // Space.Self also doesn't provide the desired results         }     } } ``

## Unable to rotate box2d body with torque if revolute joint introduced

I created a simple body (PLAYER) which, as speed increased the angle of the body increases slightly. I set the torque property based on velocity, to change the body’s angle, and it looks like the player is leaning forward as he runs. Great.

I wanted to prevent my PLAYER from flipping over (when hitting other bodies), so I created a second body and placed a revolute joint between them. The second body has rotation disabled, and is dynamic. I discovered that I did not need to apply any angle limits to prevent flipping, since the joint seemed to resist rotation. The player actually rights himself if flipped on his side. (The joint seems to want to return to 0 angle). The motor is disabled, no motor speed, no motor torque. Still, the joint returns to 0′.

The PLAYER still rotates a bit when hitting other bodies, but I can no longer rotate the body with any torque value (to make him lean forward). Why? I need to restore the leaning effect.

I don’t understand why the second body + revolute joint prevent rotation due to any torque applied. Can someone explain, and offer solution?

## Rotate Object in world space – Raytracing

I’m programming a C raytracing project.

I’ve been wanting to implement object rotations (square, cylinder) for several days but I can’t do it.

For each object, I have its position (x, y, z) in the world space and its 3d normalized orientation vector.

For the moment, I do nothing more than applying once of the three following functions on the 3d normalized orientation vector. I don’t know if I’m doing it right. Rotation doesn’t work well.

For example, I want to rotate my object left with the j key and right with the l key (x_rotation), up with the i key and down with the k key (y_rotation). I’m not sure how to use the z axis.

I will be very grateful for your help 🙂

``t_vec       x_rotation(t_vec vec, float alpha) {     t_vec   res;      res.x = vec.x;     res.y = vec.y * cos(alpha) - vec.z * sin(alpha);     res.z = vec.y * sin(alpha) + vec.z * cos(alpha);     return (res); }  t_vec       y_rotation(t_vec vec, float alpha) {     t_vec   res;      res.x = vec.z * sin(alpha) + vec.x * cos(alpha);     res.y = vec.y;     res.z = vec.z * cos(alpha) - vec.x * sin(alpha);     return (res); }  t_vec       z_rotation(t_vec vec, float alpha) {     t_vec   res;      res.x = vec.x * cos(alpha) - vec.y * sin(alpha);     res.y = vec.x * sin(alpha) + vec.y + cos(alpha);     res.z = vec.z;     return (res); } ``

## Is it possible to work out rotate in degrees per second based on this rotate logic?

I have this code to rotate an object towards another at a given speed.

``    /// <summary>     /// Rotate towards the target.     /// </summary>     /// <param name="lookPosition"></param>     private void RotateTowardsTarget(Vector3 lookPosition)     {         // Determine which direction to rotate towards         Vector3 targetDirection = lookPosition - transform.position;          // The step size is equal to speed times frame time.         float singleStep = weaponRotationSpeed * Time.deltaTime;          // Rotate the forward vector towards the target direction by one step         Vector3 newDirection =             Vector3.RotateTowards(turretYRotation.transform.forward, targetDirection, singleStep, 0.0f);          // Draw a ray pointing at our target in         //Debug.DrawRay(turretYRotation.transform.position, newDirection, Color.red, 3);          newDirection.y = 0;         // Calculate a rotation a step closer to the target and applies rotation to this object         turretYRotation.transform.rotation = Quaternion.LookRotation(newDirection);     } ``

And I’d like to convert this to a “Degrees per second” to give the user useful feedback on how quickly it rotates. Is there a formulae I can apply to work it out?

## How to rotate a rigidbody with a Pid controller

I would like someone to describe me how to use a PID controller to rotate a rigidbody with AddTorque to a specific position. (like a spacecraft that rotates the Y axis of rotation towards Camera.forward for example). Can anyone show it to me with a script?