New answers tagged

1

Quaternion.LookRotation(forward, up) gives you a rotation that points the local z+ axis (blue arrow) toward the "forward" argument, and the local y+ axis (green arrow) as close as possible toward the "up" argument. Since you want to point with the green axis instead, you can just apply an extra rotation to it: // Make a rotation that ...


1

Assuming your cylinder is oriented so that its local y+ axis (green arrow on the local transform gizmo) points along the length of the cylinder (like it does for the default Unity cylinder), then you're looking for a quaternion that rotates (0, 1, 0) to lie parallel to (target.position - pivot.position). (If that's not how your axes are set up for this ...


1

libGDXs Vector2 class has the methods you need to calculate this. By defining a barrelOffset barrelOffset = new Vector2(1.0f, -0.5f).scl(0.5f); // Relative coordinates to where the barrel is in the sprite as the relative position of the barrel in the sprite, we can figure out where the rotated barrel is by taking the position of the player and adding the ...


0

You could use trigonometry to do this. Where T is the angle: sinT = O / H H * sinT = O And you can see that O (Opposite) is basically the Y axis. Do the same with cosine, and you'll get A (Adjacent) which is basically the X axis. H would be the distance from the gun's pivot to the muzzle, and T is the angle.


2

This was years ago but I wanted to add in, for anyone curious and struggling like me, how I did this. You set the world rotation of the component in question to the value of your camera's rotations as follows. Get the PlayerCameraManager, get Camera Rotation, and break out the rotator. You're going to make a rotator for your SetWorldRotation pin and input X, ...


1

You can do this with an angle difference function: // Remaps angles into [0, 360) range on degrees. float NormalizeAngle(float angle) { return angle - floor(angle / 360f) * 360f; } // Returns the shortest signed angular delta // from angle from to angle to, in degrees. float AngleDifference(from, to) { // Wrap difference into [0, 360) range. ...


2

Following DMGregory's excellent answer and posts linked, I now understand the issue. I have implemented his function provided in one of those answers, and it works beautifully. This is my solution: I have added a new static function to my extension class, for easy access. public static class mathx { public static quaternion LookRotationExactUp(float3 ...


1

I get a lot of mileage out of this trick (see several past answers): // Find what direction points opposite our current facing direction (local z-). float3 backward = math.mul(rotation.Value, new float3(0, 0, -1)); // Find the new up vector we want to rotate our local y+ axis to match. float3 newUp = math.normalize(sphereCenter.Value - translation.Value); //...


1

Slow down your progress. Let it take more than 1 tick (if I'm reading your situation right). For example, when starting the transition - choose the desired tick duration (e.g. tickDuration = 10 ticks) and store the startedOnTick. Now in the lerp you can lerp with the progress = (currentTick + elapsedPartialTicks - startedOnTick) / tickDuration. This way you ...


0

I think your original solution was correct with one mistake: Vector3 targetVector = Camera.main.transform - transform.parent.position; Vector3 rotateVector = Vector3.RotateTowards(transform.parent.forward, targetVector, maxRotation * Mathf.Deg2Rad, 0f); // maxRotation should be updated every frame to incorporate the already applied rotation value transform....


Top 50 recent answers are included