## How can I debug a GameObject’s rotation?

I have a model of a dragon, with an animation of it flying. When I play the animation in the Animator’s preview, the dragon flies in a straight line, but when I run it in-game, it flies around in circles about 10 units in diameter.

If the turning isn’t coming from the animator, it has to be coming from somewhere else, but I have no idea where. There aren’t any scripts on the dragon that would influence it like that. Is there any way to discover what’s causing my dragon to turn? (It’s times like this that I really miss the ability to set a memory breakpoint on an object when working in .NET. That would make this trivial!)

## unity – Change item rotation axis in inventory item visualization

I’m learning unity and i’m trying now make an inventory, i made a simple interface, and now i’m trying to make a item visualization. I look for some codes from web and i found this one:

using UnityEngine;

public class TurnObject : MonoBehaviour
{
protected Vector3 posLastFame;
public Camera UICam;

// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(0)) {
posLastFame = Input.mousePosition;
}

if (Input.GetMouseButton(0)) {
var delta = Input.mousePosition - posLastFame;
posLastFame = Input.mousePosition;

var axis = Quaternion.AngleAxis(-90f, Vector3.forward) * delta;
transform.rotation = Quaternion.AngleAxis(delta.magnitude * 0.1f, axis) * transform.rotation;
}
}
}



I know some code, but I’m not good with geometrics. In this code when I move my mouse horizontal way, my object turn in the Y axis. And that’s good. But when I move my mouse vertical the object move in the X axis instead of Z axis.

Is there a way in this code for change this? I really have difficulty to understanding geometrics in Unity.

## Apple is giving trouble on each update in image rotation

Why new updates giving 180-degree rotation for landscape images? previously it was Horizontal zero. and it only makes issues on iPhone 11. this making huge issues in production websites even the developers cant predict how different apple devices behave to images. its is 21st-century and apple is still figuring out a way to capture and save images 😀

## geometry – How to get the left and right rotation quaternions between two $mathbb{R}^4$ unit vectors?

This question is somewhat similar to this, but in higher dimension.

I have two non-collinear unit vectors in $$mathbb{R}^4$$, $$bf a$$ and $$bf b$$. I know from Wikipedia that there is at least one pair of quaternions $$Q_L$$ and $$Q_R$$ that is able to rotate $$bf a$$ to $$bf b$$, i.e.:
$${bf b} = Q_L {bf a} Q_R$$
(where multiplication is the Hamilton product)

Questions:

1. What is an easy to understand and fast to compute way to find $$Q_L$$ and $$Q_R$$?
2. What are the rotation quaternions that moves $$bf a$$ towards $$bf b$$, but by a given angle $$theta$$ ?

## c++ – how to track point on object with rotation

Thanks for contributing an answer to Game Development Stack Exchange!

But avoid

• Making statements based on opinion; back them up with references or personal experience.

Use MathJax to format equations. MathJax reference.

## rotation – How do I determine the forward / right direction when I have the vector "up"? – Unit

I am trying to fix a game object, for example a cube (which I use as a sensor) on my character. I need the cube to rotate (with the inspector's orientation control – I have a set of public quaternion rotation variables). I identified 3 peaks using the ray tracing to fix my sensor on the character. I have already determined the normal of these vertices which will be the "upward" direction of the cube. I wonder how I can determine the front / right vector to use in the LookRotation () function. I basically need to be able to rotate the cube on the character even when the character is moving on the animation. This is my code, and for the moment there is no rotation. I am sure I am missing something and would really appreciate any help. I really hope this is a sufficient explanation.

 public class orientation : MonoBehaviour
{
// importing from Vertex Finder Script to use InterpolatedNormalInWorldSpace value
private VertexFinder script;
public Transform target;
(HideInInspector)
public float angleBetween = 0.0f;

// to edit orientation of sensor in Unity Inspector
public Quaternion rotation_edit;

// Start is called before the first frame update
void Start()
{
script = GetComponent();
}

// Update is called once per frame
void Update()
{
//determining the position offset of SMPL model and sensor
Vector3 relativePos = target.position - transform.position;

// aligning axes of sensor to z axis and y axis respectively
Quaternion rotation1 = Quaternion.LookRotation(relativePos, script.interpolatedNormalInWorldSpace);

// setting rotation of sensor to values entered in Inspector with respect to the above aligned axes
transform.rotation = rotation1 * rotation_edit;
}
}


## Write 500+ words SEO unique articles optimized for any niche for \$ 2

#### Write more than 500 words optimized for SEO of unique articles for any niche

We will write an article of more than 500 words with a friendly SEO and your keywords and your niche.

Are you considering buying an article for your website or blogging site?
Yes, then you have come to the right place.

What will we provide with this service?

• Quality, user-friendly content for SEO
• You can use it on your blogging sites.
• You keyword focused.
• 500 words SEO Friendly Article.
• No purchase limit per day Pe, we can provide you with an unlimited number. Please send the inbox for more details.

Order now!

.

## c ++ – Camera stutter when updating rotation via mouse input

I'm working on a camera controller for a custom c ++ / opengl engine that uses GLFW. When rotating the camera via the mouse input, I get a noticeable stutter. When I rotate the camera using keyboard input by applying a constant speed to pitch / yaw, the rotation is as smooth as the translation.

I was also able to eliminate stuttering by buffering the mouse input and applying the average, but this (as you might expect) causes a noticeable delay between moving the mouse and the rotation.

I know there has to be a simple way to do a smooth rotation with the mouse because that is what happens in all the games I have ever played … the solution is however currently escaping me. Anyone have any ideas on how to implement this?

I have included the code for my camera controller below, but if you want to see exactly what I'm talking about, you can clone the github repository (tween branch) which includes everything you have need to build, just open the solution in Visual Studio, build and you will see the stutter.

CameraController.h

#pragma once

#include

#include "glm/glm.hpp"

#include "usls/scene/stage/Controller.h"
#include "usls/scene/stage/Camera.h"

class CameraController : public usls::scene::stage::Controller
{
private:
usls::scene::stage::Camera*     camera;
glm::vec3                       moveDirection;
glm::vec3                       lookDirection;
glm::vec3                       up = glm::vec3(0.0f, 1.0f, 0.0f);
glm::vec3                       velocity = glm::vec3(0.0f, 0.0f, 0.0f);
float                           moveSpeed;

bool                            firstMouseInput = true;
float                           lastX;
float                           lastY;
size_t                          mouseDeltaBufferSize;
size_t                          mouseDeltaBufferCursor = 0;
std::vector              mouseDeltaBufferX;
std::vector              mouseDeltaBufferY;

float                           yaw;
float                           pitch;

void                            updateRotation();
void                            updatePitchYaw();
void                            updateVelocity();

public:
CameraController(usls::scene::stage::Camera* camera);
void                            logic();
};


CameraController.cpp

#include

#include "examples/es3/CameraController.h"

CameraController::CameraController(usls::scene::stage::Camera* camera) :
camera(camera),
moveDirection(glm::vec3(0.0f, 0.0f, -1.0f)),
lookDirection(glm::vec3(0.0f, 0.0f, -1.0f)),
moveSpeed(4.0f),
mouseDeltaBufferSize(5),
yaw(0.0f),
pitch(0.0f),
usls::scene::stage::Controller()
{
// fill mouse delta buffers
for (size_t i = 0; i < this->mouseDeltaBufferSize; i++)
{
this->mouseDeltaBufferX.push_back(0.0f);
this->mouseDeltaBufferY.push_back(0.0f);
}

};

void CameraController::updateRotation()
{
this->updatePitchYaw();

// rotate movement direction
this->moveDirection.y = 0.0f;
this->moveDirection = glm::normalize(this->moveDirection);

// rotate view direction
this->lookDirection = glm::normalize(this->lookDirection);
}

void CameraController::updateVelocity()
{
float currentSpeed = this->moveSpeed * this->deltaTime;

this->velocity = glm::vec3(0.0f, 0.0f, 0.0f);

if (this->input.keyW)
this->velocity += currentSpeed * this->moveDirection;
if (this->input.keyS)
this->velocity -= currentSpeed * this->moveDirection;
if (this->input.keyA)
this->velocity -= glm::normalize(glm::cross(this->moveDirection, this->up)) * currentSpeed;
if (this->input.keyD)
this->velocity += glm::normalize(glm::cross(this->moveDirection, this->up)) * currentSpeed;

}

void CameraController::updatePitchYaw()
{
if (this->firstMouseInput)
{
this->lastX = this->input.mouseXPos;
this->lastY = this->input.mouseYPos;
this->firstMouseInput = false;
}

/*
This works but feels spongy
*/
//float sensitivity = 0.2f; // change accordingly

//float xOffset = (this->input.mouseXPos - this->lastX) * sensitivity;
//float yOffset = (this->lastY - this->input.mouseYPos) * sensitivity;

//this->lastX = this->input.mouseXPos;
//this->lastY = this->input.mouseYPos;

//this->mouseDeltaBufferX(this->mouseDeltaBufferCursor) = xOffset / this->deltaTime;
//this->mouseDeltaBufferY(this->mouseDeltaBufferCursor) = yOffset / this->deltaTime;

//this->mouseDeltaBufferCursor = this->mouseDeltaBufferCursor == (this->mouseDeltaBufferSize - 1) ? 0 : this->mouseDeltaBufferCursor + 1;

//
//this->yaw += (std::accumulate(this->mouseDeltaBufferX.begin(), this->mouseDeltaBufferX.end(), 0.0f) / (float)this->mouseDeltaBufferSize) * this->deltaTime;
//this->pitch += (std::accumulate(this->mouseDeltaBufferY.begin(), this->mouseDeltaBufferY.end(), 0.0f) / (float)this->mouseDeltaBufferSize) * this->deltaTime;

/*
Works, but contains the stuttering/twitching (makes you want to puke when focusing on something and rotating)
*/
float sensitivity = 0.1f; // change accordingly

this->yaw += ((this->input.mouseXPos - this->lastX)) * sensitivity;
this->pitch += ((this->lastY - this->input.mouseYPos)) * sensitivity;

this->lastX = this->input.mouseXPos;
this->lastY = this->input.mouseYPos;

/*
Works basically perfectly, just having trouble translating this to the variable speeds from mouse input
*/
//float currentSpeed = (this->moveSpeed * 16) * this->deltaTime;

//if (this->input.keyUp)
//  this->pitch += currentSpeed;
//if (this->input.keyDown)
//  this->pitch -= currentSpeed;
//if (this->input.keyLeft)
//  this->yaw -= currentSpeed;
//if (this->input.keyRight)
//  this->yaw += currentSpeed;

// make sure that when pitch is out of bounds, screen doesn't get flipped
if (this->pitch > 89.0f)
this->pitch = 89.0f;
if (this->pitch < -89.0f)
this->pitch = -89.0f;
}

void CameraController::logic()
{
this->updateVelocity();
this->updateRotation();

// update camera
auto newPosition = this->camera->getPosition() + this->velocity;
this->camera->setPosition(newPosition);
this->camera->setLookAt(newPosition + this->lookDirection);

}
$$$$


## rotation – Rotate the rigid body with a right click

using UnityEngine;
using System.Collections;

public class drag : MonoBehaviour
{

public float catchingDistance = 3f;
bool isDragging = false;
GameObject draggingObject;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButton(0))
{
if (!isDragging)
{
draggingObject = GetObjectFromMouseRaycast();
if (draggingObject)
{
draggingObject.GetComponent().isKinematic = true;
isDragging = true;
}
}
else if (draggingObject != null)
{
draggingObject.GetComponent().MovePosition(CalculateMouse3DVector());

}
}
else
{
if (draggingObject != null)
{
draggingObject.GetComponent().isKinematic = false;

}
isDragging = false;
}
}
private GameObject GetObjectFromMouseRaycast()
{
GameObject gmObj = null;
RaycastHit hitInfo = new RaycastHit();
bool hit = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo);
if ((hit) && (hitInfo.collider.CompareTag("Move")))
{
if (hitInfo.collider.gameObject.GetComponent() &&
Vector3.Distance(hitInfo.collider.gameObject.transform.position,
transform.position) <= catchingDistance)
{
gmObj = hitInfo.collider.gameObject;
}
}
return gmObj;
}
private Vector3 CalculateMouse3DVector()
{
Vector3 v3 = Input.mousePosition;
v3.z = catchingDistance;
v3 = Camera.main.ScreenToWorldPoint(v3);
//  Debug.Log(v3); //Current Position of mouse in world space
return v3;
}

}`

## vector – Why rotating an object only on its local X axis causes sudden 180 degree changes in the rotation values ​​of the Y and Z axes

The thing to remember about Euler angles is that they are a fiction that the engine generates on demand for us. They are not the basic truth of how the rotation is stored inside the engine (which uses quaternions), and they are probably not a natural description of the reality of 3D rotation itself .

Each 3D orientation can be represented by a infinite number different triples of Euler angles – just add or subtract a multiple of 360 on any axis for example. Or combine rotations on different axes: {x: 180, y: 180, z: 0} is equivalent to {x: 0, y: 0, z: 180}

So when you ask Unity to translate the current orientation into Euler angles, it has to choose a standard version of these endless possibilities to return, which means there will be discontinuities somewhere – for example. encapsulation of {89.5, 0, 0} to {89.5, 180, 180} instead of {90.5, 0, 0}. There is simply no way to write a function mapping orientation on angles that have no looping anywhere.

The good news is that these still represent the direction you were expecting, simply written in a different way – like when a friend gives someone one of the directions to a different place than the one ; route you would have chosen, but still take it where it intended to go. 😉

This can cause problems when we have code that searches for specific Euler angle values, but the most robust solution is to not write code that searches for angle values. 39; Euler specific. (Sorry, I know that sounds clear, but after answering gamedev's questions here for a few years, I found this code that checks or maths on the angles of Euler almost never does what its author has planned for all cases that may arise in gameplay – Euler angles are very good for deceiving gamedev's intuition)

If you run into a specific bug due to this wrapping behavior, try to ask how to fix the consequences of this bug on gameplay – including the relevant code that reads these Euler angle values – and we may be able to recommend a more robust way of expressing this code.