New answers tagged

0

With a push in the right direction from DMGregory I managed to get this working after a bit of tweaking with the order of multiplication. I was probably overthinking the issue to begin with, but the code looks like this: // Find our new camera quaternion by multiplying quaternions describing l/r and u/d panning. camPos := math32.NewVector3(cam.Position().X, ...


0

There is probably a more mathematically elegant solution, but you could just offset where you are aiming based on the rotation of the gun. Say your barrel of your gun is 20px higher than your pivot point, you would calculate your angle to point the barrel based on 20px below your mouse curser to compensate. If you're aiming completely up, you would calculate ...


1

In real life, weapons have their sights (whether metallic, reddot, optical scope, etc.) slightly above the barrel axis. To compensate for this, the sights axis is usually set to point slightly down such that the sight axis and the barrel axis cross at a distance X, for example 100 m. It means that if you aim at a target 100 m away from you, the bullet will ...


1

If your object always remains upright (green vector always points up), then this is as simple as zeroing out the y component of your target direction. Vector3 targetDirection = targetToRotateTo.position - transform.position; targetDirection.y = 0f; if (targetDirection != Vector3.zero) { float singleStep = rotationSpeed * Time.deltaTime; transform....


2

If you have an object whose transform is already rotated the way you want on the z axis (and not rotated on the x and y), then this is as simple as: Vector2 direction = -transform.up; Otherwise, you can construct the rotation you want and rotate the "down" vector by it: Vector2 RotationToVector(float degrees) { Quaternion rotation = ...


0

First, note that accelerometer sensors tend to be noisy — giving rapidly varying values that jitter around the true measure, even when the device is at rest. So you'll likely want to gather up several measurements into a windowed average to smooth out this noise and get a more consistent orientation estimate. Next you'll want to measure what value the device ...


Top 50 recent answers are included