- Home /
Get the Inspector's rotation of an object with code
Hi , I have a character which in the start of the game changes its rotation with a lookAt and looks at a point . and when I see the inspector the rotations of my character are (0.66,135,0) . but when I try to debug.log my character's rotation I get (0,0,0) . I have tried :
transform.rotation
transform.localRotation
transform.eulerAngles
transform.localEulerAngles
and all of them return (0,0,0)
is there any method to return exactly what I see in the inspector?
thanks
transform.localEulerAngles should give you what you see in the inspector. Im guessing you perhaps have the script on the wrong object?
yeah you're right , sorry I had attached it to another gameObject . but my problem still exists . my game is like this : my character changes its rotation with lookAt and then it's supposed to instantiate a bullet and shoot , but the bullet goes on the previous rotation of my character . and doesn't follow the rotation of lookAt .
I think it's Csharp , if i write it in javascript , the rotation changes with lookAt . I think I have to rewrite my scripts in javascript
Your issue has nothing to do with C# or javascript. I suspect that you are not selecting the right object to use as a spawn point for the bullet, or you are using the wrong vector to apply the force. Typically I put an empty child object just in front of the gun as a spawn point. When you apply force, you can either use Rigidbody.AddForce(transform.forward), or you can use Rigidbody.ApplyRelativeForce(Vector3.forward).
Thanks , you're right it had nothing to do with C# or javascript (though I rewrote all of my scripts on javascript!) . it was the order of execution . I had several scripts which they referred to each other , i put the critical ones in one script and it worked! so far my experience in unity tells me to reduce the number of script as low as possible .