55

No this isn't an engine bug or an artifact of a particular rotation representation (those can happen too, but this effect applies to every system that represents rotations, quaternions included). You've discovered a real fact about how rotation works in three-dimensional space, and it departs from our intuition about other transformations like translation: ...


35

Fake it Look at the video you linked, watch it in slow motion... eh, what is that? The camera jumps at the end, and the knife is already in the helmet of the target. Just fake it. Once the distance from the knife to the target is small, jump cut to the knife magically in the target. Edit: you can check if it will hit a target using the convoluted ...


31

X = x*cos(θ) - y*sin(θ) Y = x*sin(θ) + y*cos(θ) This will give you the location of a point rotated θ degrees around the origin. Since the corners of the square are rotated around the center of the square and not the origin, a couple of steps need to be added to be able to use this formula. First you need to set the point relative to the origin. Then you ...


31

The answer is actually pretty easy if you do the math. You have a fixed distance of Y and a variable distance of X (See Picture 1). You need to find out the angle between Z and X and turn your turret that much more. Step 1 - Get distance between the turret line (V) and the gun line (W) which is Y (this is constant but doesn't hurt to calculate). Get ...


27

Have you considered that it looks very odd for a person to standing perpendicular to a slope? You need to be upright to stay in balance. Some alternatives: Treat his feet as a separate object and rotate them to be parallel to the slope. (A raycast will find the angle's normal, as dnk described. The angle for the feet is that + 90°.) Fake it, by moving ...


23

Multiplication At least in terms of Unity's implementation of Quaternions, the multiplication order described in the question is not correct. This is important because 3D rotation is not commutative. So, if I want to rotate an object by rotationChange starting from its currentOrientation I'd write it like this: Quaternion newOrientation = rotationChange * ...


18

It might be because of how the GamePad's deadzone works. It defaults to GamePadDeadZone.IndependentAxes, which means each axis is checked against the dead zone individually. This tends to cause the input to snap to each axis of the analog thumbstick. Instead, try using GamePadDeadZone.Circular: newGamePadState = GamePad.GetState(playerIndex, GamePadDeadZone....


16

You could decompose your quaternion into a yaw/pitch/roll set of angles, but that's overkill usually. Instead of composing your quaternions like this: cameraOrientation = cameraOrientation * framePitch * frameYaw; Try this: cameraOrientation = framePitch * cameraOrientation * frameYaw; It will then never generate tilt/roll and is equivalent to storing ...


16

Well in the simplest sense you have something like this. y |\ | \ m | \ s o | \ p v |(a) \ e (y)e |angle\ e m | \ d e | \ n | \ t | \ |__________\ x movement (x) The speed is however fast the enemy is, and you can determine how much they ...


16

Have a look at RotSprite. RotSprite is a scaling and rotation algorithm for sprites developed by Xenowhirl. It produces far fewer artifacts than nearest-neighbor rotation algorithms, and like EPX, it does not introduce new colors into the image (unlike most interpolation systems). The algorithm first scales the image to 8 times its original size with a ...


15

The angle you need to rotate by is the the angle your velocity vector makes with the positive x-axis. This angle can be calculated using the inverse tan of the slope of the vector. In XNA, we use the Math.Atan2 function. Give the function the y coordinate and the x coordinate of the velocity vector (in that order). Atan2 will return an angle between +PI/2 ...


15

The problem with rotations, is that, most people think of it in terms of Euler angles, since they are easy to understand. Yet most people forget the point that Euler angles are three sequential angles. Meaning that rotation around the first axis, will make next rotation be relative to the first original rotation, hence you cannot independently rotate a ...


14

You'll want to get a vector based on your current velocity and heading. Then use that vector to increment your position. //first get the direction the entity is pointed direction.x = (float) Math.cos(Math.toRadians(rotation)); direction.y = (float) Math.sin(Math.toRadians(rotation)); if (direction.length() > 0) { direction = direction.normalise(); } /...


14

The simple solution is not to store the orientation of the object as angles around axes (X-, Y-, Z-axis), as for instance in euler angles. Store the orientation of the object as a matrix or a quaternion. This can cause gimbal lock, using euler angles: class Object { float m_angleAxisX; float m_angleAxisY; float m_angleAxisZ; }; No gimbal lock:...


14

Automatic rotation of pixel art by other angles than 90° usually goes wrong. If you want to maintain the pixel-art aesthetics you usually won't get around redrawing your art in each angle. If you use a faux-retro look where your sprites are actually in a far higher resolution than they look, you can sometimes get away with upscaling them by an integer ...


14

If you know ahead of time where the knife will land - like in those kill cam footage, which is most definitely produced after-the-fact - just calculate the right rotation speed based on flight distance and number of rotations desired. Throwing knives leave the thrower hilt-first, so it needs to rotate N+0.5 full rotations1, where N is usually at least 1 but ...


14

Calculate the straight line distance to target. Each Frame set the angle of the knife to be 2PI*(remainingStraightLineDistance)/(originalStraightLineDistance)*DesiredNumRotations. The spin ratio will vary slightly if you don't move the knife in a straight line but no-one will ever notice. If you don't pre-determine the target (i.e. you're just throwing and ...


13

Where's the dot product used? In Unity, one of the most common users of the dot product is whenever you check if two quaternions are equal via == or !=. Unity computes the dot product to check similarity rather than directly comparing the internal x,y,z,w values. It's worth keeping this one in mind as it makes the call more expensive than you might expect ...


12

You could just store the rotations in an array like you'd store your blocks, four for each block type, then just iterate over them. That way you don't have to deal with the mess you've described.


12

Given only a point and a direction there is no defined 'right' or 'left'. Imagine being a falling raindrop, which direction is right or left for you in that case? In order to calculate (or even define) a right or left you need two directions, typically forward and up. You seem to already have a forward direction, so you need to define a up direction. ...


12

Conceptually you've got it, just think of the rectangle as a helper for you to deal with position and collision detection of your image. To implement it you could use: mySprite.image = pygame.transform.rotate(Surface, angle) This will give you a rotated Surface (image), then you can use: mySprite.rect = mySprite.image.get_rect() To give you your new ...


11

As Martin Sojka notes, rotations are simpler if you convert to a different coordinate system, perform the rotation, then convert back. I use a different coordinate system than Martin does, labeled x,y,z. There's no wobble in this system, and it's useful for lots of hex algorithms. In this system you can rotate the hex around 0,0,0 by “rotating” the ...


11

I'm not sure of a good way to preface this, other than I hope it ties together nicely by the end. That said, let's dive in: A rotation and an orientation are different because the former describes a transformation, and the latter describes a state. A rotation is how an object gets into an orientation, and an orientation is the local rotated space of the ...


11

As long as you're doing only uniform scaling, this is easy; you can simply extract each row (or column; it doesn't matter), of the 3x3 matrix. The scale factor will be the length of the row vector. If you normalize each row vector and construct a new matrix from the normalized rows, that will be the rotation part. (If you have a 4x4 matrix, you just do ...


11

You should probably use glm::angleAxis() (documentation here): glm::quat rot = glm::angleAxis(glm::radians(90.f), glm::vec3(0.f, 1.f, 0.f));


10

The LookAt function does this for you. You may be using it improperly, or something is wrong with your steering if you're having problems with this. You can try it this way too: //find the vector pointing from our position to the target dir = (Target.position - transform.position).normalized; //create the rotation to look at the target rotation = ...


10

Well, you'll have to use a little bit of physics, but you don't need to simulate any physics. There are formulas for pendulum motion you can easily use to set the rotation of your pendulum. For small swings, the motion can be approximated with simple harmonic motion. The angular displacement at a specific time can be approximated with: This is most ...


10

It’s important to note that changing the co-ordinate system with rotate and translate do not affect anything that’s currently drawn into the canvas. It only affects subsequent drawing actions. var TO_RADIANS = Math.PI/180; function drawRotatedImage(image, x, y, angle) { // save the current co-ordinate system // before we screw with it ...


9

The secret is atan2: Vector2 exitPosition = whatever; Vector2 currentPosition = whatever; Vector2 direction = exitPosition - currentPosition; float angle = (float)Math.Atan2(direction.Y, direction.X); atan2 (MSDN) gives you the angle of a vector, with the positive X axis being at an angle of zero, and moving in the positive direction towards the positive ...


9

There are 360 degrees (2π radians) in a circle. Divide that by the number of objects, and that tells you the correct angle between the objects, for even spacing. If you want to keep the objects the same distance apart no matter how many objects are in the circle, we need to calculate the distance out from the center at which points are that distance apart. ...


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