Unity3D: Contrain movement to one axis at a time - unity3d

I am making an isometric game in Unity. Im using a 3d cube as an agent for my 2d sprite. I have set up animations so that the sprite turn in the direction it is walking, however the cube is not walking in one axis at a time. Instead the cube moves in both the x and z axis, this messes up my animations. How am i suppose to contrain the cube to only walk one axis at a time so that the animations turn out correctly.

If your cube has a Rigidbody attached, you can check the axis you want to freeze under Rigidbody > Constraints > Freeze Rotation.

Related

how to get mouse drag direction in unity

Hello guys I am building a 3D game that player can reshape something like slime with dragging it. the shaping part is alright and I do not have a problem with it.
I use mesh manipulation for shaping my object and I move all vertices within a specific radius of clicked position. but my vertices are moving toward its normal vector I figured that out I can move vertices toward mouse drag vector by just changing normal vectors.
so, here is my question how can I get mouse drag vector so I can change my normal vector to that?
also the player can rotate around X And Y Axis on my object and this makes this problem a little more difficult.
because for example if I see my object from this angle (270,0,0) if players drag mouse to right and down my object should Stretch to its -x Axis and -z Axis.

Shader is not working properly in my 2d game

I was looking for doing a sprite wave like water on a lake/ocean, i found a tutorial on internet, but it was for a 3d game, i applied the tutorial but the shader is moving the sprite in the Z axis, so the wave effect is not notizable from 2d view, but in 3d view it looks fine, it's a 2d game so i need it to move in the correct direcction, this is my first shader so i don't understand it so much.
Use a x=0, y=1, z=0 vector instead of the Normal Vector node.
That will make the wave motion go in the "upward" direction on the object instead of the "outward" direction.

Controlling rotation path in Unity3D

On my top down 2.5D shooter game, I am usingQuaternion.LookRotation() and Quaternion.Lerp() to change the rotation of my player towards a click. The player rotates just fine, but I need more control over the rotation path. The issue here is that the LookRotation() always returns the shortest path to complete the rotation. I need the player to always rotate only in the X axis until its either +90 or -90 and then flip in the Y axis to the other side. It doesn't matter if the player rotate + or - 90 degrees over the X axis, but the idea is to always rotate in the X axis, before flipping from 1 frame to another, then rotating again in the X axis towards the click.
Here are some images illustrating the above. The "X" in red below, is where the "click" happened.

Unity 2D polygon collider

Is there a way to create 2D polygon collider to work as as perimeter collider?
I want to be inside the polygon and do a raycast to the border. I want the hitpoint to be on the border, not on the location where I am.
Can I use 2D polygon collider for that or do I need to use some other collider?
You could create a polygon shape with 2D Edge Colliders. Just calculate the different spots with the polygon's angles.
I noticed there was an answer saying this already. My bad. :)

How can i add right collider for a cylinder with hold inside?

I have a cylinder with a hole inside.
I did the cylinder in blender and exported it to unity.
The problem is that the character walk through the cylinder and i want the character to walk inside but not through.
So i added a capsule collider component to the cylinder.
Now when the character walk in there like a floor since i changed the collider Center on Y to -1.5 and the Radius to 2 and the Height to 4.
The problem is if i will change the collider to be higher then the character will not be able to walk in the hole.
The collider component on the cyolinder settings in the inspector:
Either you put a meshcollider , or a mix of sphere and box colliders.