New answers tagged

0

I had this same issue, I was using sprites with 8 different directions of movement. Here's how I detected which direction they were moving in: The way the sprite is facing depends on the direction they were last moving in. You can find the direction of sprite movement by performing some calculations on their original coordinates, and the coordinates of ...


2

NOTE: Edited because it was likely too verbose (source). A rotation matrix actually always defines an orthonormal basis. What this means is each column defines one of your original axes in its rotated state. For example, consider a simple rotation matrix around the z-axis (more on rotation matrices here). Let's say we plug in Pi / 2, in other words, we ...


-1

Here is the code I use to get the angle of a 2d vector, hopefully it is what your are looking for. (using our own library functions, most of which should be obvious) float zVec2f::getAngle () const { //straight up, 0.0f degrees zVec2f up(0.0f, -1.0f); //angle between up vector and our vector zVec2f normal = *this; if ( ...


0

Indeed, you need an additional orientation hint for this to work. It is quite common to use an “up” vector in addition to the view vector that you computed. Most 3D libraries have some kind of “lookat” function: Transform.LookAt in Unity3D, glm::lookAt in glm, or the deprecated gluLookAt in ancient OpenGL. Note that if the “up” vector is constant or only ...


1

So I guess you could save like the last 10 rotations in a List and get the average of them with this function. The function return could be set as your final rotation. This should smoothen your rotation. private Quaternion calcAvg(List<GameObject> rotationlist) { if (rotationlist.Count == 0) throw new ArgumentException(); float x, y, ...


0

Okay, I finally fixed it after several hours. Problem was, my parent plane in Maya was set to something like 6,3 / 2,1 / 3,1. So this was the scaling the object always got imported into Unity, which messed up its space / pivot points. In Maya I now just used Modify->Freeze Transformations on the Plane, to normalize it to 1 / 1 / 1. After that I had to ...


0

You need to rotate the rocket after each "physics" update (I think you are not actually using rigidbodies or physics), like so: You just need the rocket's transform.forward to always point in the same direction as its' velocity, regardless of how you calculate velocity. If "forward" is always pointing in the actual correct direction, you can just push the ...


0

try this: put an empty game object a few units below the rocket, but horizontally in the middle of it. (the more units below the rocket, the slower the rotation will be ). use this code ( just a concept ) //note that this code won't work like this, it's just a guideline public float speed = 0.2f; void Update () { if (outOfFuel) ...


1

Ok, after 4 hours of searching finally I found the mistake. Problem was with the sprite origin. Here's the line that was necessary (staticBody is the body around other bodies will rotate) tmpSprite.setOrigin(staticBody.getPosition().x / 32 + tmpSprite.getWidth() / 2, staticBody.getPosition().y / 32 + tmpSprite.getHeight() / 2); And here's ...


0

Introducing a rate of change to the current heading Heading= 050 Change= 0.2/second (Current Heading + Rate of Change*Time)=New Heading (050+0.2*1)=50.2 (050+0.2*2)=50.4 (050+0.2*3)=50.6 (050+0.2*4)=50.8 (050+0.2*5)=51.0


1

You could rebuild the spears orientation matrix from a direction vector. Good example with dx code is here.. http://stackoverflow.com/questions/4237873/rotate-a-sphere-so-that-its-pole-heads-towards-the-camera/4237921#4237921


0

Solved my problem! I read an approach in XNA 3.0 Game Programming Recipes: A Problem-Solution Approach, and adapted it to my needs. Here's the code if anybody is curious: Matrix4 upTransform = Matrix4.createRotateY(yrot); // find the height at the front, back, left, and right Vector3 frontLeft = upTransform.transform(new Vector3(-SCALE / 2, 0, ...


1

You just need to keep track of how much rotation you've applied, and break out of the loop when you reach your target: IEnumerator rotationRoutine() { runRotationRoutine = false; rotating = true; var total_z_rot = 0.0f; while(rotating == true) { // prevent from over-rotating var z_rot = Mathf.Min(360.0f - total_z_rot, ...



Top 50 recent answers are included