unity – Rotate around moving object

You can store your current pivot object, direction from it, and distance away in member variables.

Overwrite these values when you start rotating around a new pivot, but then keep the distance variable fixed at that value for future updates.

In your Update (or LateUpdate, if you want to be sure this runs after any Update scripts or animations that move your pivot objects around), rotate your direction, scale it by your distance, and add it to the pivot position to find your new location relative to it.

Here’s one way that could look:

public class RotateAround : MonoBehaviour {

    public float rotationSpeed = 90f;

    Transform _pivot;
    Vector3 _offsetDirection;
    float _distance;

    public void SetPivot(Transform pivot) {
        if (pivot != null) {
            _pivot = pivot;
            _offsetDirection = transform.position - pivot.position;
            _distance = _offsetDirection.magnitude;
        } else {
            _pivot = null;

    void Update() {
        if (_pivot == null) return;

        Quaternion rotate = Quaternion.Euler(0, 0, rotationSpeed * Time.deltaTime);

        _offsetDirection = (rotate * _offsetDirection).normalized;

        transform.position = _pivot.position + _offset * _distance;

plotting – Rotate and translate previously-plotted data

I have the following:

Show[data1, data2, data3,PlotRange -> {All, All}]

where data1, data2 and data3 are of the form Plot[g, {x, 0, 100}, ImageSize -> Large, ....etc.]

How can I both translate and rotate the data that I see in Show for data1, data2 and data3 without modifying the g of the data itself?

The translation part was solved by both @Michael E2 and @MarcoB here: Shift data of the form `Plot[g, {x, 0, 100},ImageSize->Large,….etc.]`. Here’s the code from @Michael E2 that only gives translation:

p1 = p2 = p3 = Plot[Sin[x], {x, 0, 2 Pi}]

 MapAt[Translate[#, {0, 0.1}] &, p2, 1],
 MapAt[Translate[#, {0, 0.2}] &, p2, 1],
 MapAt[Translate[#, {0, 0.3}] &, p3, 1],
 PlotRange -> All

unity – 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 with the character control script below. However, I don’t know how I can do a slide/crouch.

What I want to do is 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.

this is basically the motion I want to do but, but in all the axis

I thought about making the player rotate on a specific axis but when he turns the axis doesn’t change so now I’m kind of lost in what to do.

using UnityEngine;

public class PlayerMovement : MonoBehaviour

    public CharacterController controller;

    public float speed = 10f;

    //turnning smoothness

    public float turnSmoothTime = 0.1f;
    float turnSmoothVelocity;

    //jump controls

    public float jumpHeight = 3f;
    public float gravity = -29.43f;
    Vector3 velocity;
    bool isGrounded;

    //gravity check
    public Transform groundCheck;
    public float groundDistance = 0.4f;
    public LayerMask groundMask;

    // Update is called once per frame
    void Update()
        isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

        if(isGrounded && velocity.y < 0)
            velocity.y = -1f;

       //player movement on both axis

        float horizontal = Input.GetAxisRaw("Horizontal");
        float vertical = Input.GetAxisRaw("Vertical");
        Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
        velocity.y += gravity * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime);

        if (Input.GetKeyDown("space") && isGrounded)
            velocity.y += Mathf.Sqrt(jumpHeight * -2f * gravity);
        if (direction.magnitude >= 0.1f)
            //player turning depending on where moving

            float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg;
            float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime); 
            transform.rotation = Quaternion.Euler(0f, angle, 0f);
            controller.Move(direction * speed * Time.deltaTime);

How to rotate objects in Solar System game?

I have to implement this game as seen in figure (right is a UML class diagram as a reference).
The Moon rotates around the Earth (faster) and Earth rotates around the Sun(slower).Both of them are counterclockwise rotations.
enter image description here

How to make it work?

networking – Rotate VPN on Router Automatically

I am running DD-WRT on my router with a VPN configured. I would like to have the VPN rotated through a database of VPN server addresses.

Ideally a script would SSH into the router and change the VPN settings and there would be no down time (or perhaps a few seconds). But from what I’ve read the router must be rebooted after the VPN settings are updated, which would take awhile.

Are there any solutions to have a VPN setting on a router changed on the fly with a script with very little down time?

I am open to using any open source router firmware, it does not have to be DD-WRT.

Thank you.

unity – Why the rotation using the Coroutine is rotating but the object is in slant ? and how to rotate it with Coroutine non stop?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Spin : MonoBehaviour
    public Vector3 targetRotation;
    public float duration;
    public bool spinInUpdate = false;

    // Start is called before the first frame update
    void Start()
        if (spinInUpdate == false)
            StartCoroutine(LerpFunction(Quaternion.Euler(targetRotation), duration));

    // Update is called once per frame
    void Update()
        if (spinInUpdate == true)
            transform.Rotate(new Vector3(0, 1, 0));

    IEnumerator LerpFunction(Quaternion endValue, float duration)
        float time = 0;
        Quaternion startValue = transform.rotation;

        while (time < duration)
            transform.rotation = Quaternion.Lerp(startValue, endValue, time / duration);
            time += Time.deltaTime;
            yield return null;
        transform.rotation = endValue;

slant I mean this is how it’s rotating with the Coroutine the small cube that rotate is in slant :


When using the Update way it’s rotating fine and this is how it should rotating also with the Coroutine for example on the X only :


The small cube when rotating either in update or in the Coroutine should not be slant. but it’s slant in the Coroutine.

And how can I add a speed factor to the Update to control the rotation in the Update in case using the Update ?

About controlling the speed in the Update I just added a global float variable and in the Update :

transform.Rotate(new Vector3(0, Time.deltaTime * rotationSpeed, 0));

and it’s working for the speed.

mathematics – Rotate relative to set point in a specified direction in a 3D space

I know there’s a geometry formula to calculate the next point in rotation relative to another point in 2D but I’m working in 3D and I want to calculate the next position in specified direction as well. Think Spiderman or the Bloodstalkers from ARK. I’m working in a game engine that uses the basic {x = 1, y = 2, z = 1} for vectors. I’m pretty bad at math so I honestly can’t figure this out myself.

rotation – Unity – Rotating Minimap – Boundary Icons don’t rotate

I’ve followed some tutorials to get icons to clamp at the boundaries of my square minimap. Each icon is a child object of gameobjects that will show up on the radar. This child has the following in its minimapIcon script;

void LateUpdate() {

    <something here using main.camera y rotation?>

    transform.position = new Vector3(
        Mathf.Clamp(transform.position.x, MinimapCam.position.x - MinimapSize, MinimapSize + MinimapCam.position.x),
        Mathf.Clamp(transform.position.z, MinimapCam.position.z - MinimapSize, MinimapSize + MinimapCam.position.z)

The MinimapCam script, attached to a game second camera (minimap) positions and rotates the minimap based on where the main camera is facing;

void LateUpdate() {
    Vector3 newPosition = player.position;
    newPosition.y = transform.position.y;
    transform.position = newPosition;
    transform.rotation = Quaternion.Euler(90f, Camera.main.transform.eulerAngles.y, 0f);

But I’ve noticed the minimap icons clamp in a set square boundary and do not follow the rotation of the map.

Any idea how I can rectify this? I feel I have to add the main.Cameras y rotation into minimapIcon but I’m not sure how.

Using quaternions to rotate an object (OpenGl,c++)

I started to learn quaternions and got very weak idea of how they work. So I blindly followed some tutorials on you tube on how to rotate object with glm.
I had problem with weird rotations when I used Euler angles once I switched to Quaternions rotation was normal, but now rotation gets fuzzy in terms that it changes speed, when it should be constant.

glm::vec3* rotationAngles = modelVertex->getRotation();

glm::mat4 translate = glm::translate(glm::mat4(1.0f), *modelVertex->getPosition());

glm::mat4 mQuat = glm::mat4_cast(glm::normalize(glm::angleAxis(glm::radians(rotationAngles->x), glm::vec3(1.0, 1.0f, 0))));

return this->perspective *translate * mQuat;

rotationAngles->x is constantly increasing by some constant (20 degrees)

In my loop I have code that goes angle+=20; and then rotation.setXAngle(angle);

Funny thing is this only happens when I’m using rotation on both x-axis and y-axis, when for example I only rotate on x-axis,speed does not change.

rotation – Rotate & Translate a MatrixTRS

Hello I have a question about translation & rotation of a MatrixTRS…

So basicly I have a given MatrixTRS A in space, define by a positionA, rotationA and scaleA.
(DISCLAIMER: I am using Unity, but I do not use Transform, therefore I have a Matrix4x4, created like that:
Matrix4x4 A = Matrix4x4.TRS(position, rotation, scale);

Ok, Now I have a Point in space, with a given rotation, named PositionB, and RotationB.
I would like to translate & Rotate my TRS matrix to that positionB, and rotationB.

I know I have to do something like b.transform.TransformPoint() and Quaternion.Inverse(b.transform.rotation)*a.transform.rotation, but i didn’t manage to make it right yet.