# Tag Info

4

Multiplying two quaternions gives you a quaternion equivalent to performing the two rotations they represent in sequence. q3 = q1 * q2 q3 * object = q1 * (q2 * object) // "Perform rotation q2 with respect to the world axes, then q1" // Or equivalently: "Perform rotation q1 about your local axes, then q2" q4 = q2 * q1 q4 * object = q2 * (...

4

You can calculate the correct physics world gravity with the help of the acceleration method in the Input class. Physics2D.gravity = 9.82f * Input.acceleration.normalized; The code example above uses a gravity force of 9.82f, and by multiplying that value with the device' accelerometer value (normalized so it's between 0.0f and 1.0f), the physics world's ...

4

Gimbal lock occurs when your internal structure for storing/composing rotations uses a gimbal model: Image via Wikipedia, attributed: "By Lookang many thanks to Fu-Kwun Hwang and author of Easy Java Simulation = Francisco Esquembre - Own work, CC BY-SA 3.0" That is, when you construct your orientation as a sequence of component rotations with ...

3

It doesn't know. What it does is point the local z axis of the object (that's the blue arrow you see in the scene view when selecting its local transform gizmo) in the forward direction you pass to LookRotation, and the local y axis (green arrow) as close as possible to the upwards direction you pass, or world up if you didn't provide a second argument. By ...

2

What should I add to transform.InverseTransformPoint (transform.position) to get transform.localPosition? Add parent: transform.parent.InverseTransformPoint(transform.position) == transform.localPosition transform.localPosition is the position of this object in its parent's coordinate system. transform.InverseTransformPoint() transforms a position from ...

2

I found out what is wrong. Apparently, the rotation of the gun finished only after the projectile was spawned. (It's weird because it doesn't happen usually). This fixed it: The setting in red is the default one. Any of the green settings are good enough for this solution to work. I hope that someone with similar issue finds this one day and saves some time ...

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, ...

2

This becomes obvious if we walk through the loop step by step. Let's say your duration is 1 second, we're running at 30 FPS, and the object starts with Euler angles (0, 0, 0): On the first loop, we blend between (0, 0, 0) and (0, 90, 0) by a factor of 1/30. 0 + (90-0)*1/30 = 0 + 90/30 = 0 + 3, so that brings us to the angles (0, 3, 0) On the second loop, ...

2

You should use SpriteRenderer's FlipX property.You dont need any kind of Vector scale operations just simply use SpriteRenderer's builtin property Example public class CharacterHeadFlipScript : MonoBehaviour { public SpriteRenderer characterHeadSpriteRenderer; // just drag and drop the sprite renderer of your character's head via editor void ...

2

Finally I solved the issue and it was related to wrong image positioning as @Tyyppi_77 has mentionned in the comments. The blit method of pygame.Surface turns out to blit a surface in the topleft corner if coordinates are passed to the 2nd parameter. However, if we pass a Rect object, we would be able to position the image as we want. Here is what the ...

2

First of all, I want to say, I sympathize. I have gone down the path of making a custom variation of a Node by composition and turning it into a scene and then having to rely on reaching deep into the structure to use it. And I have also implemented property delegates for ease of use. The current Godot response is Editable Children. You can instance a scene ...

2

Is it possible to apply something to qx or qy to get the original q directly? Yes it is! The transformation you're looking for is $qy^{-1} * qx * qy$ (My reasoning is like looking at a unit vector starting in the x direction, which if I rotate 45 degrees in the y axis would give me a vector pointing in the z=x direction, but this is clearly naive as it ...

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 = ...

2

You still handle it in the usual way. Make 3 perpendicular unit vectors (an orthonormal basis), expressing the directions your object's local axes should point after rotation: // Forward Y = forwardHeading; // Right X = Normalize(Cross(Y, (0, 0, 1)); // Up Z = Cross(X,Y); And then use these three vectors as the columns of a matrix: $$\vec {\text{rotated}} ... 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 This line: transform.localRotation = Quaternion.Euler(camRot, 0f, 0f); ...says "throw out whatever rotation you had before, and replace it with this one that I constructed from one Euler angle" So any rotation you worked hard to make on the yaw axis is discarded, and you end up with pitch-only rotation, because that's what you've provided on the ... 1 When you assign a value to transform.right/up/forward, you're implicitly telling Unity "I care only about the direction of this one axis - do whatever is cheap and easy with the other two". If you care about both the up and forward direction, then you need to take responsibility for constructing a quaternion with your desired orientation. ... 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.... 1 I'll be referring as agent to the opponent controlled by the game. And agent controller to the code that, well, controls the agent. You can have an abstraction for your agent controller, and still allow continuous movement. To do that, you would have code to translate between those representations. That is, the agent controller would understand the game in ... 1 Your code assumes that MoveRotation(rot) takes an increment to add to the current rotation. That's not what it does. It takes an absolute orientation to move to, completely discarding the previous orientation. So by passing just the travel of the mouse in this frame, your rotation will snap back to zero yaw anytime the mouse stops moving. It looks like you ... 1 You can get the difference between the two transformations by multiplying the new one by the inverse of the old. (If these matrices are pure rotations, with no translation/scale/shear, then this inverse is just the transpose)$$R_\text{diffference} = R_1 \times R_0^{-1} Now you can extract the quaternion representing the rotation from this difference ...

1

Assuming your rotation variable is an angle in radians around your object's origin point, and your point variable is an offset vector relative to the origin in the object's local coordinate space, then this is simply: public static Vector2F CalcPointWithRotation(Vector2F origin, Vector2F point, float rotation) { float c = (float)Math.Cos(rotation); ...

1

A 4x4 homogeneous matrix can represent any affine transformation. That is, any combination of: Translation by any offset Rotation around any axis by any angle Scale along multiple arbitrary axes by any scale factor Shearing in any plane by any factor Including any arbitrary composition of the above, in any order - like rotating then scaling then rotating ...

1

Assuming you have the Transform for your target object, and the Transform of the body the head is attached to, you can compute whether it's on the left or right side of the body by looking at the sign of the dot product: Vector3 toTarget = target.position - body.position; float dot = Vector3.Dot(toTarget, body.right); if (Mathf.Approximately(dot, 0f)) { ...

1

Your character object should have vectors representing its facing (forward, right, up). If you take the normalized right vector and multiply it by a scaling factor, you will create an offset vector. Add the offset to the player position and store it in a separate variable. This is where your camera will rotate around, roughly speaking. Don't forget to update ...

1

It seems you have not really understood what the functions you use actually do. The Time.fixedDeltaTime, as per the documentation, returns the time between each physics update in seconds. This is a fixed value (e.g. for 50 physics updates per second this will be 0.02). Now, lerpTime is also a fixed value in your case from my understanding. This means that in ...

1

For similar questions; cglm povides a few pe-defined rotation APIs (new more APIs may be added in the future if needed): rotate vector using axis/angle glm_vec3_rotate(vec3 v, float angle, vec3 axis) apply rotation matrix to vectoo glm_vec3_rotate_[m4 | m3](mat4 m, vec3 v, vec3 dest) rotate vector using quaternion glm_quat_rotatev(versor q, vec3 v, vec3 ...

1

First of all, game engines and math go hand in hand so understanding the underlying theory should be high in your priority list. I will try to explain this at a high level, based on what I understood and will try to elaborate later when I get the time. I will also put in bold terms you should look at. Taking the spiderman swinging example, this means you ...

1

The Z you are assigning is taken as the distance of the point along the ray produced in the viewport; which corresponds to all the world points stacked on that screen point. The higher the Z, the farther it is from the camera. That being said, based on the information you provided, I suspect you want to use ScreenPointToRay here, perform a raycast, then ...

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