Hello all!
I rotate my Object in World Z Axis using this:
var speedHorizontal : int ;
speedHorizontal = Input.GetAxis("Horizontal") *100* Time.deltaTime;
transform.Rotate(0,0,1*speedHorizontal,Space.World );
it works.So far so good.
What I really need: I want to create variable which will control local rotations (rotation to specific angle).
Rotation should look like this: transform.Rotate(1,0,0, Space.Self);
I was trying to use code below, but it doesn’t work:
transform.localRotation.x = localAxisRotX
I have recorded video to show my problem:
var MoveHorizontal : int ;
var MoveVerical : int ;
var localAxisRotX : float ;
function Update ()
{
MoveHorizontal = Input.GetAxis("Horizontal") *100* Time.deltaTime;
MoveVerical = Input.GetAxis("Vertical") *300* Time.deltaTime;
transform.Rotate(0,0,1*MoveHorizontal,Space.World) ;
// transform.Rotate(1*MoveVerical,0,0,Space.Self);
transform.localRotation.x = localAxisRotX ;
}
Thank you for reading, and even more thanks for any answers or suggestions!
It’s not working when my object is rotating in space.world on Z Axis
I could put my object in EmtptyGameObject and then use Transform.Rotate Z axis in space.world to rotate,
and inside on my Object use your code to rotate in local.x. , but i thing it should be better way to do this.
var MoveHorizontal : int ;
var localAxisRotX : float ;
function Update ()
{
MoveHorizontal = Input.GetAxis("Horizontal") *100* Time.deltaTime;
transform.Rotate(0,0,1*MoveHorizontal,Space.World);
transform.localEulerAngles.x = localAxisRotX;
}
I need this to rotate object in Z axis in space.world.
I need additional rotation in X axis in space.local, and I want to
control this with variable which I could use to specific angle.
woow its working Thank You ,
but now there is another problem. I need this object to work with rigidbody, because now when is falling on the ground, the rotation is frozen.
Is the different way to get this local rotation.x ?
I control my Object with this : transform.Rotate(0,0,1 * localAxisRotZ, Space.World);
and I have added some forces. It looks pretty good.
But my problem is that I need add this local rotation. Physic doesn’t work on rotation with your code.
Is it any solution for that?
OK, here is the conundrum that you are in… You want to specify an angle, but then have the object collide with things. This actually counteracts what you are trying to do.
That being said what you are looking for is half math, half physics. Its not easy to do, and without knowing what your trying to accomplish, just giving you code to do it will not really help you. (since giving you code hasn’t really helped you thus far.)