Tag Info

New answers tagged

0

Maybe you spawn it too close/inside other colliders. Try spawning it at some distance.


1

I haven't digested all of your code. Consider the effect of using the center of the rear axle as the vehicle's origin and have that point ride the actual Bezier. As such, the car's forward direction is coincident with the tangent. Both of these relate to the path of a real car. The front wheels just need to always point directly toward their ...


0

You can use transform.localPosition to determine the position of the child object relative to its parent. The normalized version of this vector, .normalized, can be multiplied with the parent's scale to get the desired local position. You might want to set the scale of the parent to 1 and position the child accordingly if you don't already do so. ...


0

If you have a circle sprite, that you want to rotate around a point other than its center, there is a much more effective way than this. Just go to the circle sprite in assets, and change the pivot of the sprite to the edge you want it to be. And that's it, you should get a rotation around that pivot, and when you scale, it'll stay the same. And don't ...


1

The camera up-vector A property of the camera you could use to solve this problem is the up-vector. This vector indicates which direction in 3D space should correspond with the (upward) vertical axis of your screen. Usually, cameras will use the positive y-axis for this, thus: (0, 1, 0). The scalar product of two vectors The scalar product of two 3D ...


1

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


1

//Everything normalized shipRight = shipForward.Cross(target.Up); shipUp = shipForward.Cross(shipRight); The cross-product is perpendicular to both vectors. For this diagram, I gave both spheres random orientations. The left view shows the steps from an arbitrary, third, perspective; I couldn't find a better alignment, so you'll have to take my word that ...


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


0

It seems like your transformations might be accumulating over time. As repeatedly "stepping forward" and "rotating around your axis" will cause the black bar to walk in circles. I'm unfamiliar with Unity, but there are some general approaches that might be applicable: You could try recalculating the object's position from its starting position, rather than ...


0

void Update () { //if you are past the amount of degrees, then you don't need to rotate more. if (this.transform.rotation.eulerAngles.z > /*amount of degrees*/ 5.5f) return; //rotate more this.transform.Rotate (0, 0, 0.1f); } Or better, I would make a quaternion of the starting angle and the end angle ( using: ...


0

Ok the problem turned out to be a typo in the way meshes were being loaded. It caused the Z terms of each vertex to be resolved to the X term... If anyone comes across this and wants to know here is my properly working mesh loader method. public static Mesh loadMesh(String fileName){ String[] splitArray = fileName.split("\\."); String extension = ...


0

Can't comment yet so I post it as an answer, but it appears that you should have a - at ry.m[2][0] and + at ry.m[0][2] when looking at the 3d rotation matrices. Does not make a difference though for an x-only rotation as both of these evaluate to 0.


1

You simply lerp between these angles. Here is a part of my third person character controller script, that smoothly rotates the model in the direction that it's moving: Vector3 angle = Vector3.zero; if(moveDirection.x != 0) { if(moveDirection.z == 0) { if(moveDirection.x > 0) angle.y = 90; else if(moveDirection.x < 0) ...


0

You need to do this as a hierarchy. Have a main Object that you move and run all your code on, and then add the sprite as a child object and rotate the sprite object only so it aligns the way you want it to.


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

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


1

You need to clamp the vertical rotation. I don't know off the top of my head the simplest way to adjust that code, but it'll just involve changing a couple lines around the transform.RotateAround() stuff, to use Mathf.Clamp() for the angle around the x-axis. I think you just need to put in y = Mathf.Clamp(y, -180, 180); right after incrementing y. This way ...


1

The key is to analyze how an actual camera would work. If you're pointing it toward, say, a wall in front of you, then you point it toward the ceiling, and then keep turning it "up" you will find that the ground will actually start to come into view from the top. It seems odd at first - but the actual camera configuration you have is already "correct" IMO. ...


1

I avoid Euler angles in aircraft pitch, roll, yaw orientations because aircraft rotate about thier local axis and trying to resolve this to Euler angles about the world (or global) axis adds uneccesary complication to the code. Instead of 3 Euler angles, I store the current orientation as a matrix or quat and simply modify the matrix/quat depending on input ...



Top 50 recent answers are included