- Home /
Question by
Cryptospook · Jul 05, 2018 at 06:45 AM ·
unity 2d
how to rotate only on the z axis in 2d game,how to rotate only on the z axis
im trying make my character move and rotate towards a virtual joystick. the character moves in the right direction but rotates on the x and y axis making the character invisible. how can I make this rotate only on the z axis?
void Start ()
{
myBody = this.GetComponent<Rigidbody2D>();
}
void Update ()
{
Vector2 moveVec = new Vector2(CrossPlatformInputManager.GetAxis("Horizontal1"),
CrossPlatformInputManager.GetAxis("Vertical1")) * moveForce;
transform.LookAt(transform.position.toVector2() + moveVec);
bool isBoosting = CrossPlatformInputManager.GetButton("Boost");
myBody.AddForce(moveVec * (isBoosting ? boostMultiplyer : 1));
}
Comment
Try changing LookAt like this:
transform.LookAt( (transform.position.toVector2() + moveVec) - transform.position.toVector2() );
As far as I can tell that just rotates the x axis -90
Your answer
