Hot answers tagged

5

This is entirely a matter of convention. (Since you didn't mention any particular tools.) But! If you are modeling in the same default orientation as your screen, which you say is right-handed, X-right, Y-up, and therefore Z-towards-you, then it would be natural to model your characters facing you, where forward is Z-positive. Which also implies your ...


4

Rotations are extremely order-dependent. Doubly so when you're composing rotations in local space (so the axes you're rotating around are themselves rotating from one frame to the next) As an extreme example, imagine that you start facing z+, and in one frame you pitch (x rotation) 90 degrees up. In the next frame, you yaw (y rotation) 90 degrees left. ...


4

Use Transform.TransformDirection() method where Transform is your player transform. // Calculate the x-axis relative to the camera camera = Camera.main.transform; cameraRelativeRight = camera.TransformDirection (Vector3.right); // Apply a force relative to the camera's x-axis rigidbody.AddForce (cameraRelativeRight * 10);


4

At 90 degrees, you can work out rotations in both directions just by swapping and reversing positions. Begin with the following shape: Ahead, we rotate it manually clockwise, and look at the resulting positions (grey dots are rotated positions): Analyzing point B's position: Before transforming, it was (1, 2). After transforming, it was (-2,1). If you ...


4

A simple way to achieve this effect would be to launch the missile with an initial velocity of (ship's backwards vector + ship's rightwards vector), then apply a constant acceleration of (ship's forward vector) each frame, until it reaches some maximum forward velocity. Of course, that describes a "dumb" rocket that always follows that (rightward) ...


3

From the docs on transform.Translate: public void Translate(float x, float y, float z, Space relativeTo = Space.Self); If relativeTo is left out or set to Space.Self the movement is applied relative to the transform's local axes. (the x, y and z axes shown when selecting the object inside the Scene View.) So because you have not specified a ...


3

I was able to get the rotations expected by rotating an accumulated rotation matrix. setIdentityM(currentRotation, 0); rotateM(currentRotation, 0, angleY, 0, 1, 0); rotateM(currentRotation, 0, angleX, 1, 0, 0); // Multiply the current rotation by the accumulated rotation, // and then set the accumulated rotation to the result. multiplyMM(temporaryMatrix, ...


3

The problem your having is called gimble lock. I think what your looking to do is called arcball rotation. The math for arcball can be abit complicated. A simpler way of doing it is finding a 2d vector perpendicular to the 2d swipe on screen. Take the vector and project it onto the camera near plane to get a 3d vector in world space. Screen space to World ...


3

There are a couple ways. This way shows how you can do it at runtime by grabbing out all the vertices to build the BoundingBox around the model. The first answer on this page is super old but the basic idea applies to use a custom processor for your model in the content pipeline so you can compute the BoundingBox and store it in the Tag property of the ...


3

Whatever collision be, angular momentum is conserved. ie Iw = constant with the coefficient of restitution (in translation, i dont know if its said the same in rotation) u define, and with the moment of inertia, you should be able to figure it out. And i think this would similar to collisions in 1D, since only one axis is used :) Goodluck :)


3

You're in luck. I did a full translation of Randy Gaul's 2D physics engine into C# and XNA. He hasn't really explained things well for beginners like me. For your answer, you should just multiply the cross product with the inverse of the inertia of the body. This is from my translation: angularVelocity += inverseInertia * Vector2D.Cross(contactVector, ...


3

Calculate the dot product to determine how close two vectors are. The dot product is 1 when they are exactly the same, -1 when they are exactly opposite, 0 when they are perpendicular, and decimal values when partway. So take the current direction, the target direction, then Vector3.Dot() and check if greater than .9 (or whatever threshold you decide looks ...


3

I found the solution myself. Here's what I've done: I took the default forward rotation of the firingPoint object, and split it into it's parts - x, y, z, w. Then from these floats, I create a new Quaternion using the constructor method: float randomX = Random.Range(-0.1f, 0.1f); float randomY = Random.Range(-0.1f, 0.1f); float randomZ = ...


3

Your problem is not that tricky : you do have a formula that will give you the next position (at t+dt), given the current one. Now say the projectile is at P : use the formula to get the next point NP : D = (NP-P) is the direction vector at t. Now depending on what you seek : • Angle ? Get the angle (atan2) of this D vector, to have the angle of your ...


3

Okay so imagine the image below is the front view of one of your faces on your cube: Ugly, I know. Currently when you do FACE.setRotationAxis(Rotate.X_AXIS) you are setting the rotation axis of that individual square to be the center of the square. The black dots in the image below are your rotation axes: So when you say to rotate, each cube rotates ...


3

In the case of a puzzle like this you can animate the rotation then reset the model back to its original position but with the cube's stickers rotated. Look at it like cheating with a real puzzle by moving the stickers. You'll have to make it possible to change the stickers' colors. This can be done with material colors or a dynamic texture. And this way ...


2

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));


2

The trick here is conversion between world space and screen space. World space is the coordinate system you use for your game logic - calculations of pathing, movement, formations, etc. Your original formation code is correct for world space. Screen space is the coordinate system in which items are displayed. Because you're using an axonometric projection ...


2

if (Math.abs( angle) > mindelta ) transform.LookAt (currCustom); I think it depends on floating point math errors, I suggest to define a min angle (mindelta in my code example) inside wich, the turret doesn't move


2

So with your provided problem image, the problem is that the top side of the quad is being affected, while the right side is supposed to have the majority of the effect? Is that correct? If that's the case then the problem is that your passing the wrong values to your ZHandler.getz function. Your code, from what I'm seeing, is: glTransform glBegin ... ...


2

Try: Debug.Log(moveHorizontal), and that sheds a lot of light on what's happening. If you're using a keyboard, what happens when you press d, is not that moveHorizontal snaps from 0.0f to 1.0f. It gradually increases. It goes from 0.0f, to 0.1f, then maybe 0.3f, and so-forth, until it eventually becomes 1.0f. The final value of it being fully pressed. What ...


2

Iterating through the faces: faceNormal[i].dot(-worldViewVector) > 0.8 //(should actually be >0.9999) If you do an if/switch to apply a rotation to the cube(or camera): Just update and store a value indicating the front face at the same time. This actually works the same for non-snapping angles such as your scene view. In the orthogonal mode, the ...


2

Your problem is transform.up = TowardOrigin;. I didn't know you could actually set transform.up until now, since it's actually a summary of a more complex state of the object -- its rotation. Setting it tells Unity to orient your object along that axis, but doesn't tell Unity to keep transform.forward as close as possible to what it used to be. You're ...


2

glRotatef and glTranslatef are old functions meant for use with the fixed-function pipeline, so they don't work with opengl 4 shaders. Instead you need to create a matrix, send it to your shader, and multiply your vertices by it when setting gl_Position. The exact process will probably be covered in one of the following tutorials on that site, so I'd ...


2

This is a script that keeps the rotation of the head to the rotation you set in the script, however it is very simple and may need adjustment to your purpose.(I have included sliders for easy editing). I hope this answers your question. using UnityEngine; using System.Collections; [ExecuteInEditMode] // This allows it to run during editmode(Makes it easier ...


2

jhocking's answer about dot product is the right answer to the question, but if you are rotating your object over time to face the right direction, inside that function you must be calculating how much you have left to rotate so that you know what direction to rotate and so that you don't rotate too far and overshoot. That means that inside that function, ...


2

First, it won't solve your problem, but there are a few general problems with your code. The conditions for your if branch will always be true if transform.localEulerAngles.x >= 0 and <= 360. The > 270 part is redundant since if x is less than 270, it is still possible to be >= 0. If x is 0 and lookAxisX is > 0, then adding -lookAxisX will make x < ...


2

Something like this: transform.position = player.transform.position - player.transform.forward * distance; transform.LookAt(player.transform); where float distance is the distance of camera form player Consider also the solution 2 : Make camera child of player and in your player die script , you can "deatach" camera from player object transform.parent ...


2

You can use Quaternions instead of Euler Angles to solve this. transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(rotationDestination), Time.deltaTime * rotationSpeed); If you want to test distance still, you can use... if(Quaternion.Angle(transform.rotation, Quaternion.Euler(rotationDestination)) > 0.2f) I'd suggest you ...



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