# Tag Info

## Hot answers tagged rotation

7

The Problem: Your eyes default rotation makes them look to the negative X axis. However, Transform.LookAt() rotates the transform, so that the Transform.forward looks at the target. The Transform.forward always looks to the positive Z axis. (All directions in local space). Solution 1: Rotate the texture or mesh, so that the eye's default look direction is ...

5

You can check simple ahead/behind relationships using the dot product: Vector3 displacement = B.transform.position - A.transform.position; float dot = Vector3.Dot(displacement, A.transform.forward); If dot is greater than zero, then B is ahead of A along A's forward vector. (The arrow from A to B has a component in the same direction as A's forward) If ...

3

It looks like there is garbage in your mousePosOld variable when you first detect a click (through if (Input.GetMouseButton(0))): it seems you use an uninitialized value for it (most likely (0, 0)) for the first click, or the value you got from the last time you had mouse-down. Assuming you'll not get a mouse click event on the first frame, you could update ...

3

If each call to Update calls a coroutine, then you are creating a new coroutine each update and each coroutine will run in parallel with those created before. Your object will rotate faster and faster, while your framerate will get lower and lower due to the huge number of coroutines executed in parallel. That's unlikely to be what you want. If you want to ...

2

Turns out my quaternion rotations are completely fine. Positive rotations are CCW in right-handed coordinate systems[1]. My rotation matrix functions were the ones rotating backwards! And in fact they were transposed by mistake. [1] https://www.evl.uic.edu/ralph/508S98/coordinates.html

2

The reason it is not rotating correctly is because the forward vector or z axis of the modal is not pointing to the tip of the rocket. To solve it, either set the forward vector in some 3D modelling software or just create empty gameobject and assign the script to it, then make rocket as the child of empty object and rotate it in a way that the tip points ...

2

Unity's OnMouseDown / OnMouseDrag / etc MonoBehaviour messages only work when the object has a collider attached. This is because when you use these methods, under the hood, the engine fires a physics raycast each frame from the main camera, through the position of the mouse, to find out what object is under it, so it knows what object to fire these ...

2

To make this work in the same way as your League of Legends example, you need to put a Text inside a Widget component which is attached to your character, not TextRender. The reason for this is that you can set the Widget to display at the same location in world or screen space so it moves with the character and does so automatically with rotation. Create ...

2

What's happening here is two things : You are just applying the camera rotation to the text instead of billboarding the text You are rotating all the axes of your text, when you need to rotate it on one axis only What you can do instead : Use Find Look At Rotation, with your billboard and camera position as inputs http://api.unrealengine.com/INT/...

2

Input.GetAxis() returns the velocity of the axis in that frame. For example, getting the x-axis from a controller with a joystick will return the same thing as if you had moved your mouse to the right a certain amount. Input.GetAxis() will not tell you the overall movement of the mouse over multiple frames, or the position of the mouse on the screen. To get ...

2

atan2 expects the Y parameter first. See this SO question for answers as to why the Y parameter is passed in first.

2

Turns out the solution to the fundamental problem is to avoid the complicated math and just use an appropriately-configured HingeJoint. When a player grabs an object, set node A to a kinematic body child node of that controller, and set node B to the object being grabbed. Set both paths to empty strings when they let go. The actual result is a little wonky, ...

2

It looks like you're mixing up & combining two different ways to rotate an object: Slerp and RotateTowards. Your code has elements of each, but uses neither correctly. We could implement this with a Slerp, or Spherical Linear Interpolation (where you blend from a start orientation to an end orientation using a progress variable): float rotationProgress ...

2

Why have we arrived at the convention that rotations should be counter-clockwise then, even in engines where positive y is down? Have we? Let us try CSS: const box = document.getElementById("box"); function step(timestamp) { let deg = timestamp/10; box.style.transform = "rotate(" + deg + "deg)"; window.requestAnimationFrame(step); } ...

2

A spline key input is a bit like an index into the spline. A spline is generally formed from control points, similar to a Bezier curve. My knowledge on this is rusty, but the idea seems to be that the starting point has the value of 0.0f, and is increased by 1.0f (by default) per point, so a minimal spline out of two points goes from 0.0f to 1.0f while one ...

1

This is my solution, Google Earth like control with smooth animation (or not), when zoomed in it is user friendly and slows panning down. The only thing I am not satisfied about is the quaternion slerp, at these defaults there won't be any sudden jumps but I would have loved to understand how to sub-interpolate quaternions so it works even when rotating ...

1

Waited more than I expected. I found a simple solution for this. Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector2 direction = new Vector2(mousePos.x - transform.position.x, mousePos.y - transform.position.y ); transform.up = direction;

1

New Answer Since you have two vectors to begin with, instead of two quaternions, Find the quaternion representing the rotation from one vector to another. Then you can take a copy of the current rotation quaternion, and multiply it with the quaternion you got from the vectors, which gives you the final rotation quaternion. You can then lerp from your copy ...

1

I used the method @DMGregory suggested and rotated the joint before setting the limits. Since the joint limits rotation and also cannot be disabled I created a script that rotates and then adds the joint. public class ConfigJoint : MonoBehaviour { private ConfigurableJoint joint; [SerializeField] private Rigidbody connectedBody; [Header("...

1

Okay so the goal is to be able to rotate a rectangular, which I'll call sprite, to line up with an arbitrary point in 2D space, which I'll call target. Rotating sprite to line up with target can be achieved through the Transform.LookAt method provided by Unity, however this alignment will be based upon sprite's center, and we would rather have the target ...

1

From what I understand the fact to compute your angle on Viewport space messes everything up due to origins. If you do your computation on Screen space everything will work just fine. Update your code with this: var p2 = Input.mousePosition + Vector3.forward * transform.position.z; var p1 = Camera.main.WorldToScreenPoint(transform....

1

This is easier than you think! // Get the vector toward the next waypoint from here. Vector3 forward = TargetWaypointPos - transform.position; // Get the local "up" vector pointing out of the planet to here. Vector3 up = transform.position - SphereCenterPos; // Form an orientation that points the z+ axis along "forward", // and the y+ axis as close as ...

1

The simple answer here is vector projection. If n is a unit vector (length 1), then... float projection = Vector3.Dot(n, someVector);` is the signed length of the component of someVector that's parallel to n. We can subtract that component to leave only the perpendicular component: Vector3 perpendicular = someVector - n * projection; It looks like you ...

1

if (y + translate >= 50) { y == 50; } This doesn't actually do anything. y goes out of scope right after. Instead you want to limit the value of translate.

1

The reason you see the rapid back and forth movement as it tried to align itself to the player's axis is because of overshoot, as you probably guessed. I reconstructed what I believe you are trying to do using Vector3.MoveTowards instead. This function is useful because it does not overshoot. Unfortunately this code is untested so let me know if it works. ...

1

you need polar coordiates. you need to find the position in polar coordintaes(radius,teta) to unity basic cartesian coordinates(x,y) you can move the object by changing the theta angle this is my example code: private void FixedUpdate() { foreach (var item in PolarElements) { float x = item.radius * Mathf.Cos(item.myAngle); ...

1

As I mention in the linked answer, for full 6 DoF controls like spaceflight or swimming, it often works well to think of a corrective twist that you gradually apply to reassert your desired horizontal plane. Here's one way we can do this: First, we'll track a normal for the plane we want the ship to orient to when the player is not deliberately rolling. ...

1

I was tempted to vote to close this as primarily opinion-based, but we may be able to provide an evidence-based argument here. I'd recommend that your method rotate counter-clockwise for positive angles, for the sake of interoperability, and mathematical convention: Interoperability As you've pointed out, Unity's API already picks a side by using left-...

1

Doing this requires high-level mathematics (college/university), so it's no wonder those are the only solutions you found. If you know how matrices work, it's pretty simple. I already described how you can get a rotation matrix from a normal in this post. Your problem is the exact inverse of this: instead of going from points in the XY plane to a rotated ...

1

You can get a rotation matrix from a a direction ($\vec d$) and an up vector ($\vec u$) (direction is the normal here). First you need to get 2 perpendicular vectors, one pointing to the right ($\vec r$) and one pointing up ($\vec t$) when looking in the direction of the normal vector. You can get $\vec r$ by getting the cross product of \\$\vec d\...

Only top voted, non community-wiki answers of a minimum length are eligible