Tag Info

Hot answers tagged

5

Start by adding a variable for the angle that the car is moving at. float angle = Math.Pi / 2; Then add a variable for the current speed. float speed = 0.0; Now create three constants: public static final float acceleration = 0.1; public static final float maxSpeed = 5.0; public static final float rotationRate = Math.Pi / 50; For starters, get your ...


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

Create an empty gameobject, make it child of your gameobject. Move it to one of the corners you want to rotate about, Use RotateAround to rotate your gameobject. You could also do the same through code by calculating the dimensions of your gameobject. Edit: You could use these scripts to make your life easier: PivotManager, SetPivot.


4

One way to do it is to keep track of the Front and Up normalized vectors and transform the front vector whenever your character turns, and calculate the Right vector using cross product ( I am assuming Up vector won't rotate). Or you can keep track of the three vectors and rotate them. Once you rotate them you update the position by adding the offset in the ...


4

This is a late response, but I figured this question illustrates a common problem that many people are likely to run into and that deserves an answer. Quaternion rotation uses half the angle you want to rotate by. Since you (in this example case) are rotating by 90 degrees, the quaternion needs to calculate the sine and cosine of 45 degrees, both of which ...


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


3

Not sure if this is the most performant, but it can be visualized easily: //assuming you're starting with a relatively orthonormal matrix 1.) Take one of your matrix's 3 basis vectors and dot it against the 6 world orthogonal vectors and set it to the one whose result is closest to 1.0. 2.) Do the same for one of the 2 remaining basis vectors. 3.) Cross ...


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

This problem is called Forward Kinematics. To solve this problem in general, I recommend creating what is called a Kinematic Chain, or Kinematic Tree. To do this, you will need knowledge of a 2D rotation matrix, or transformation matrix. A 2D 3x3 transformation matrix is defined as: H = [xx, xy, tx; yx, yy, ty; 0, 0, 1]; In this case, [xx, ...


3

I'd expect the conversion to be more like: static XMVECTOR XMConvertToQuaternion(XMFLOAT3 axis, float radian) { return XMVectorSet(sin(radian/2)*axis.x, sin(radian/2)*axis.y, sin(radian/2)*axis.z, cos(radian/2)); } in particular there is no need to push the coordinates through a cos and the w should be the last coordinate, there is a micro optimization ...


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

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

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


2

When facing this problem I found that I wanted the character to move forward at a velocity roughly proportional to how close they are to facing the target. When facing away from our target we "turn on the spot" (Red), when facing directly towards it we walk straight towards it (Green), when somewhere in between we will may walk slowly while turning (Blue ...


2

Try sprite.setOriginCenter(); This should help


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

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


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

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



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